Monday, December 9, 2024

Use Jenkins CI/CD Pipeline to Deploy Kubernetes Pod/Deploy/Service on AWS EKS

 In this blog, I'll try to list down the steps needed to use Jenkins (Deployed on an EC2 Machine) to utilize the AWS EKS (Managed K8S Service) and use Kubectl commands to create Service/Deployment and Pods on EKS.

Steps:

1. Deploy Jenkins on Amazon EC2. I have used Amazon Linux AMI.

2. You can use files from my public Github repo: https://github.com/pkumar8789/sample-k8s-jenkins.git



Once your Jenkins is Up & Running:

Install required Plugins: In this case, Install Kubernetes CLI & Kubernetes Plugin



Configure the Jenkins to connect to EKS Server:

Click on Clouds --> New Cloud

Scroll down and Go to Credentials

Use the option of Secret File.

*** This secret file should be the KubeConfig file post you have set the Kube Context. I have provided a sample KubeConfig file in my Github repo.

Kubeconfig file is generally created using the command below

aws eks --region $(terraform output -raw region) update-kubeconfig --name $(terraform output -raw cluster_name)

https://developer.hashicorp.com/terraform/tutorials/kubernetes/eks

Create a New Item in jenkins and use the below Jenkins pipeline format to connect to EKS and execute kubectl commands:

Note: We are having one additional step to do AWS Configure to set the user profile.