Setup Aws EKS Cluster With Fargate Profile With Terraform Code by jenkins Pipeline

We will setup Aws EKS cluster with terraform by Jenkins pipeline. To be able to do that we need to have some dependencies as you can see below screenshot. Because as you know Jenkins pipeline will need to run these commands to be able to do its job. We have already installed terraform, aws cli, kubectl in our Setup Jenkins Pipeline article.

Please visit that article to install dependencies if you donโ€™t have. And please remember that you need to have latest versions of aws cli and kubectl for compatibility, otherwise pipeline might fail because pipeline first create eks then connect to update kube config file with aws cli and use kubectl to make some changes like patching coredns deployment for fargate profile. If kubectl and aws cli versions are not compatible with each other then kubectl might fail to update coredns deployment.

If you have older version of aws cli then you can update with below commands;

rm /usr/bin/aws

cd /tmp

curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”

apt install unzip

unzip awscliv2.zip

./aws/install -i /usr/local/aws-cli -b /usr/local/bin

 

If you have older version of kubectl then you can update with below commands;

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg –dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

echo ‘deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /’ | sudo tee /etc/apt/sources.list.d/kubernetes.list

apt-get update

apt-get install -y kubectl

 

Here are commands to install helm;

curl https://baltocdn.com/helm/signing.asc | gpg –dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null

apt-get install apt-transport-https –yes

echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main” | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list

apt-get update

apt-get install helm

 

Now letโ€™s go to Jenkins console and create a pipeline to deploy aws eks cluster. Login to your Jenkins console and click on New Item in Dashboard Screen. Here is the pipeline script that you can download and apply for your own requirements. You just need to change variables at the top of the pipeline under environment {} block so it is going to create your eks cluster with fargate profile according to your values. I should tell you that iam_user_name variable is for the user that you want to give permission to manage eks via kubectl or view eks resources in aws console. You can write your own user name not to fail pipeline or another user name that you want to give permission.

Pipeline Script Github Url:

https://raw.githubusercontent.com/semiharsan/devops/main/jenkinspipelineforawseksclusterwithfargatehttps://raw.githubusercontent.com/semiharsan/devops/main/jenkinspipelineforawsekscluster

aws eks cluster

 

This pipeline is going to create an Eks cluster with aws load balancer controller so you can directly deploy your apps into EKS and publish them to public internet via load balancer controller.

As you can see below, coredns and load balancer controller pods are ready to use. Now you can publish your apps to the world ๐Ÿ˜Š

 

If you want to destroy all EKS resources that we created by terraform code via Jenkins pipeline. You just need to configure pipeline and change terraform apply with destroy as shown in below screenshot.

setup aws eks cluster

 

Well done guys. We just created Aws EKS cluster with terraform code by using Jenkins pipeline. You can just copy pipeline and change variables to create another EKS cluster. Please check out our deploying python app into EKS cluster article from below url.

 

 

<< GO TO SETUP JENKINS ON UBUNTU LINUX SERVER >>

<< GO TO DEPLOY PYTHON APP ON AWS ECS SERVICE BY JENKINS CI/CD PIPELINE >>

<< GO TO HOW TO DEPLOY PYTHON APP MAIN POST >>