Posted By da Agency
AKS with Terraform on Rancher Shared as a Service





  • AKS with Terraform on Rancher Shared as a Service
    Photo by Youhana Nassif on Unsplash

    In this short tutorial I’m going to show you how to deploy an AKS cluster with Terraform and import the created cluster into Rancher. If you don’t have access to a running Rancher environment, you can get instant access to our free forever Rancher Shared as a Service environment running on Kubernautic or run Rancher with a single docker run command on you local machine.

    $ docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher:stable
    $ open https://127.0.0.1/

    If you’d like to try this tutorial, please ensure you have the following prerequisites met before you start:

    • Azure CLI 2.9.x (check with az version)
    • Terraform 0.12.x (check with terraform version)
    • Access to Kubernauts RSaaS or your own Rancher environment
    • An Azure subscription and permissions needed to deploy AKS clusters and its contents

    First of all, you need to create an app registration for you soon-to-be AKS cluster. Afterwards, login to Azure and head to the Azure Active Directory section. Click on App registrations in the left column and register a new app. Then, give it a name and decide, if it is for single tenant or multi-tenant usage. Next, click on the fresh app registration. It’s mandatory that you create a secret which can be done at Certificates and secrets (copy the secret for later usage).

    Get the source on Github

    Next, we need to prepare the Terraform scripts. You can use the scripts from this GitHub Repo.

    You can change the settings in the “.tf” files to your desired values, especially in variables.tf, where you can set the cluster name, resource group and other important values.

    After having prepared those files, you will need to export the following environment variables with the values from the app registration:

    export TF_VAR_client_id=APPREGISTRATION_CLIENT_ID

    export TF_VAR_client_secret=APPREGISTRATION_CLIENT_SECRET

    Now, we are going to prepare Terraform for the deployment. Initialize Terraform with terraform init. Next, you need to lock the deployment which will be done with terraform plan -out out.plan. If everything looks right, start the deployment while referring to the plan with terraform apply “out.plan”. This might take a few minutes before the deployment is finished.

    Validate, that your AKS deployment was successful, by getting the credentials and log in to your new cluster with

    az aks get-credentials -n YOUR_CLUSTER_NAME -g YOUR_RESOURCE_GROUP

    and, after you’ve gathered the credentials, kubectl cluster-info.

    When you have set up the cluster, move over to the Rancher and hit Add Cluster. Choose Import an existing cluster and add the prompted values. After the import, you will be shown a new site. There are commands which need to be run on the cluster. Run this command on your fresh AKS cluster and it will appear on your Rancher dashboard.

    Please note: Rancher will to show you an error message regarding the Controller Manager and Scheduler. Please ignore this notification, due to a bug coming from AKS. The occurring problem is already known and being discussed. Also, it is addressed. Nevertheless, a good solution might take some time. You can find some more information about this issue here.

    Well done and congratulations, you now have successfully deployed an AKS cluster using Terraform and imported it into Rancher 🙂

    About me:

    I work as a Senior Cloud and DevOps Consultant for Kubernauts GmbH in Cologne, Germany. My main goal is to guide everyone on who are on their way to the cloud, regardless if it is a company or a single private person. If you have any questions or ideas for improvements feel free to contact me on LinkedIn or on GitHub

    AKS with Terraform on Rancher Shared as a Service


    AKS with Terraform on Rancher Shared as a Service was originally published in Kubernauts on Medium, where people are continuing the conversation by highlighting and responding to this story.

    Mehr zu Kubernetes Services, Kubernetes Training und Rancher dedicated as a Service lesen unter https://blog.kubernauts.io/aks-with-terraform-on-rancher-shared-as-a-service-64209e34ad23?source=rss—-d831ce817894—4