Kubernetes and Terraform Automation – IaC

Kubernetes and Terraform Automation – IaC

GKE cluster automation using terraform and manifest.


Deploying your application on Kubernetes cluster is like getting the maximum outcome of your application while you are totally free mind to manage your application instances and when you able to provision your Kubernetes cluster on GCP using any IaC (Infrastructure as code) tool like terraform it will be so much helpful in your DevOps process.

So here is a flawless procedure I would like to share with you which I recently deployed in my cloud ecosystem, and my Kubernetes cluster is highly Available, super scalable fault and strong fault-tolerant now, the application is running flawlessly without a single hassle.

Below is my approach to creating a GKE on GCP using terraform and k8s manifest files and on the top of Kubernetes there is one app is running used from my docker hub image.

  1.  Terraform IAC (infrastructure as a code) script to create a GKE on GCP:- I used WSL on my windows 10 so on the top of ubuntu I have installed the GCP Cloud SDK and terraform on my local laptop from where I used to execute all DevOps commands to create the GKE Cluster as required.

No alt text provided for this image

terraform init
terraform plan -out 'devops-plan-GKE.plan'

2. The terraform apply output once successful of execution of the IAC script completion

There are 2 files for terraform providers.tf, main.tf, and variables.sh to create GKE using terraform with where I have declared the value of machine type, min, and max no of nodes in the pool.

terraform apply 'devops-plan-GKE.plan'

3. Once the GKE cluster is successfully created you need to create credentials to your KUBECONFIG (~/.kube/config) so that you can interact with this cluster and once its done next step to execute your k8s deployment and service to deploy your application and load balancer respectively so the application can interact with end-users using the interest.

gcloud container clusters get-credentials <cluster-name> --region us-central1

kubectl apply --filename hello-k8s-deploy.yaml
kubectl apply --filename hello-k8s-svc.yaml

the output would be like below once you successfully executed the application deployment and services in your Kubernetes cluster.

No alt text provided for this image

4. The manifest file also using my docker hub image (meetravi007/ravi-app:v1.0) for creating deploying the app in pods. please refer to my GitHub repository shared in this article.

5. Once successfully k8s cluster deployment is completed you can able to get load balancer external up for end-user use over the internet.

No alt text provided for this image

No alt text provided for this image

6. you can run the web application using LB external IP

No alt text provided for this image

7. All required terraform files and yamls is available on my GitHub but they are not public, as mentioned in the task, we may have an online demo if you like my approach to taking this task, sorry I didn’t get much time to do other task mentioned due to also having some current project work in parallel.

               Thank you, 😊 Ravi Bhargava

Links: –


Leave a Reply

This Post Has 3 Comments

  1. Mark Edward

    Great article! It helped me alot to configure my k8s and terraform, Thanks for sharing

  2. sikis izle

    Because the admin of this site is working, no doubt very shortly it will be well-known, due to its feature contents. Chloette Niels Fredela

  3. film

    Great advice!! May I have the courage to speak up at such a time. Kriste Bronnie Gelasias