MULTI CLOUD KUBERNETES SETUP USING ANSIBLE TERRAFORM

Buddhiprakash Jain
8 min readJul 12, 2021

Hello EveryOne!!🖐

In this blog I am going to Create 💥Multi_Cloud_Kubernetes_Setup_Using_Ansible_Terraform Where 👨‍💻User can deploy Kubernetes 🌍Environment on Multi Cloud in Single 📌Click. For the dynamic inventory process, the most latest approach is used which includes dynamic IP retrieval with an ansible plugin.

Multi_Cloud_Kubernetes_Setup_Using_Ansible_Terraform

Technologies that are integrated for this Project:-

⭐Ansible

⭐Kubernetes

⭐TerraForm

⭐AWS Cloud

Google Cloud

Azure Cloud

For Deploy Multi Cloud k8s Setup you Need to Follow Certain Steps :-

🔰Download Code from my GitHub Repo:-

❗GitHub URL :-

STEP 1:- Setup Environment for AWS Cloud

STEP 1:-

Install the required software.

Install software

STEP 2:-

Create IAM user and save access key and secert key temporary anywhere.

Create I

STEP 3:-

Export AWS credentials on terminal or for permanent put your credential in /root/.bashrc file.

Export Credentials

💎 AWS_ACCESS_KEY_ID=<access_key value retriving from STEP2>

💎 AWS_SECRET_ACCESS_KEY_ID=<secret_key value retriving from STEP2>

STEP 4:-

Change in file aws_instance_tf ➡ aws.tf

❄Profile Provide IAM username.

❄ami ➡ Provide ami-id of amazon linux 2.

❄key_name Provide your keyname.

❄security_groups Provide Security Groups.

Change in aws.tf file

STEP 5:-

Put your Instance Key in k8s_master_aws folder in .pem format.

Put Instance Key

STEP 6:-

Change the value of private_key_file in k8s_master_aws ➡ ansible.cfg file

Change private_key_file keyword value

✅By Performing Above Steps k8s Environment for AWS Cloud is Setup.

STEP 2:- Setup Environment for GOOGLE Cloud

STEP 1:-

Install the required software.

Install software

STEP 2:-

Create a service Account IAM & Admin ➡ service accounts and give power to it.

Create Service Account

STEP 3:-

Generate ssh key in your vm.

Generate Key

STEP 4:-

Copy the content of file my_key.pub from ~/.ssh folder

copy file

STEP 5:-

Paste the content of my_key.pub file in google cloud

💥Location > Compute Engine ➡ VM Instances ➡ Metadata ➡ SSH Keys ➡ Edit ➡ Add item

Paste Keys

STEP 6:-

Create keys in google cloud json key and p12 key.

🔷IAM & Admin ➡ service accounts choose your service account click on keys click ADD Key and create new key both json and p12.

Create Keys

STEP 7:-

Copy *.json key in google_instance_tf folder.

copy json file

STEP 8:-

Change name of *.json file to service-account.json

change .json key file name

STEP 9:-

Change in file google_instance_tf ➡ google.tf

⚡Project ➡ Give your project name.

⚡Credentials ➡ Give your json file

Change in file google.tf file

STEP 10:-

Change .p12 key in pem format.

Change key format

🔰Give your key name at place of pkey.pkcs12

STEP 12:-

Copy your .pem key file in k8s_worker1_google folder.

Copy pem file

STEP 13:-

Change the value of remote_user in k8s_worker1_google ➡ ansible.cfg file

Change in file

🔰NOTE :-Give remote_user value here those you give username in STEP3.

STEP 14:-

Change in file k8s_worker1_google ➡ gcp.yml.

📌Projects ➡ Give your project name

Change in file

✅By Performing Above Steps k8s Environment for Google Cloud is Setup.

STEP 3:- Setup Environment for AZURE Cloud

STEP 1:-

Import packages for Azure

Run command ➡ sudo rpm — import https://packages.microsoft.com/keys/microsoft.asc

Install Packages

STEP 2:-

Make repo for Azure

Copy given below👇 content and run together for making Azure repo.

cat > /etc/yum.repos.d/azure_cli.repo << EOF
[azure-cli]
name=Azure CLI
baseurl=https://packages.microsoft.com/yumrepos/azure-cli
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
EOF

Run on Terminal

STEP 3.1:-

Install Azure

Install Azure

STEP 3.2:-

Install Azure CLI Software

Install Software

STEP 4:-

Login to the Azure portal

Login to the Azure Portal

STEP 5:-

Automate login screen come up on your vm browser and give username password of your account.

Login Portal

STEP 6:-

After giving username and password you got msg that is shown given below picture

Login Successfully

STEP 7:-

Retriving id’s of Azure account for futher use

STEP 8:-

SUBSCRIPTION ID

💥Location > Go to Resource group ➡ choose your resource group ➡ their you will get Subscription id.

Subscription ID

STEP 9:-

CLIENT ID

TENANT ID

SECRET ID

💥Location >Go to Azure Active Directory ➡ Go to App Registration

App Registration

Click on New registration and create new registration with any name

New Registration

Now click on registration those you create in above there you will find both tenant id and client id

Client id and Tenant id

Now click on Client Credentials and create new client secret

Create client secret

Value is your secret id those highlight in your color

Secret id

STEP 10:-

Assign the Role to the App registration that you create in STEP9

💥Location > Go to subscription ➡ Select Access control(IAM) ➡ Click on Add role assignment(Preview)

Assign Role

Select Contributor and click on next

Select Contributor

Click on select member

Select Member

Search your App by name and select it

Select App

Click on next and then click on assign role

Assign Role

STEP 11:-

Export AZURE credentials on terminal or for permanent put your credential in /root/.bashrc file.

Export Azure Credentials

STEP 12:-

Create ssh key in Azure Cloud

Go to SSH-keys and create new key their and download it

Creating SSH Key

STEP 13:-

Copy public key file with .pub extension in azure_instance_tf folder key name can be anyname in my case it is master.pub

💥Location of .pub file > Go to resource group ➡ choose your resource ➡ their you find your key those you create in step 12 ➡ Click on that key name and copy public key

Public key location
Copy SSH-Key

STEP 14:-

Change in azure_instance_tf ➡ azure.tf file

💥resource_group_name ➡ Your resource name

change resource_group_name

💥public_key ➡ Your public key name

Change public_key

💥subnet-id ➡ For Retriving subnet-id run given below command on your azure cli

Run this Command on Azure cli

📌Change group name and vnet name in above command

id

Choose default id that is at number one

change subnet id

STEP 15:-

Copy .pem(those you download in STEP 12)file in k8s_worker2_azure folder .

Copy Azure pem file

STEP 16:-

Change in k8s_worker2_azure ➡ ansible.cfg file

📌private_key_file > Give your private key file name those you copy in STEP 15

Change ansible.cfg file

STEP 17:-

Change in k8s_worker2_azure ➡ myazure_rm.yml file

📌include_vm_resource_groups > Your resource group name

Change in myazure_rm.yml file

✅By Performing Above Steps k8s Environment for Azure Cloud is Setup.

STEP 4:- Configure Multi Cloud Setup

STEP 1:-

RUN setup.yml file for configuring

Run setup.yml file

After run setup.yml file completely Multi Cloud Kubernetes Setup Using Ansible and Terraform Deploy Successfully.

STEP 2:-

Login into the AWS Kubernetes master node and run command that is given below

check cluster

✅Now you can see Multi Cloud k8s Cluster is Ready.

If you liked the above blog , please Clap and Share it.

DM me on LinkedIN in case of any Suggestions/queries/feedback.

❗GitHub URL :-

❗LinkedIN URL :-

Thank You🙏🙏

--

--