Skip to content

timoteosoutello/devops-azure-aks

Repository files navigation

DevOPS - Azure AKS Cluster via Terraform (using Github Actions / Azure DevOps)

Requirements:

  • The Azure Account created
  • The Service Principal set up and Initial state in place.
  • Set the variables to make the repo be cleaner
    • For Azure CLI
      • AZURE_CREDENTIALS
    • For Terraform CLI (used in CI/CD Tools)
      • For authentication
        • AZURE_CLIENT_ID
        • AZURE_CLIENT_SECRET
        • AZURE_SUBSCRIPTION_ID
        • AZURE_TENANT_ID
      • For backend state
        • RESOURCE_GROUP_NAME
        • STORAGE_ACCOUNT_NAME
        • STORAGE_CONTAINER_NAME

CI/CD

Using Github actions (.github/workflows/) or Azure DevOps (cicd/azure-dev-ops) it was created the following YML files:

  • The az-terraform-create-cluster.yml - For resources creation
    • After the creation, result would be like below
      • The Terraform State:
      • The Cluster:
  • The az-terraform-destroy-cluster.yml - For resources destruction

CI/CD Troubleshoot

Common errors:

  • Error building ARM Config: obtain subscription() from Azure CLI: Error parsing json result from the Azure CLI: Error waiting for the Azure CLI: exit status 1
    • Solution: Ensure that you passed the correct AZURE variables as mentioned above
  • A task is missing. The pipeline references a task called 'TerraformInstaller'. This usually indicates the task isn't installed, and you may be able to install it from the Marketplace: https://marketplace.visualstudio.com. (Task version 0, job 'prepare', step ''.)

Configure kubectl

To configure kubetcl run the following command:

$ az aks get-credentials --resource-group {{resource_group_name}} --name {{kubernetes_cluster_name}}

Outcome should be:

$ Merged {{kubernetes_cluster_name}} as current context in {{LOCAL_DIR}}\.kube\config

Configure Kubernetes Dashboard

To use the Kubernetes dashboard, we need to create a ClusterRoleBinding. This gives the cluster-admin permission to access the kubernetes-dashboard.

$ kubectl create clusterrolebinding kubernetes-dashboard --clusterrole=cluster-admin --serviceaccount=kube-system:kubernetes-dashboard  --user=clusterUser

Finally, to access the Kubernetes dashboard, run the following command:

$ az aks browse --resource-group {{resource_group_name}} --name {{kubernetes_cluster_name}}

You should be able to access the Kubernetes dashboard at http://127.0.0.1:8001/.

Login with kubectl config

References

Microsoft

Terraform

External references

About

Kubernetes cluster in terraform for Azure

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages