๐ Part 5 Kubernetes CI/CD Automation: Best Practices with Jenkins, GitLab, AWS, and Azure


1๏ธโฃ Overview
CI/CD (Continuous Integration & Continuous Deployment) automates the build, test, and deployment process, ensuring rapid and reliable delivery of Kubernetes applications.
๐น Why CI/CD for Kubernetes?
โ
Automates application deployment โ Reduces manual effort
โ
Ensures consistency โ Deploy the same way across different environments
โ
Supports multi-cloud โ AWS, Azure, and on-premise clusters
๐ Table of Contents
1๏ธโฃ Jenkins Pipeline for Kubernetes CI/CD
2๏ธโฃ GitLab CI/CD for Kubernetes
3๏ธโฃ AWS CodePipeline for Kubernetes Deployments
4๏ธโฃ Azure DevOps Pipeline for Kubernetes Deployments
5๏ธโฃ Best Practices & Troubleshooting
1๏ธโฃ Jenkins Pipeline for Kubernetes CI/CD
๐น Step 1: Install & Configure Jenkins
1.1 Launch an EC2 Instance for Jenkins
Instance Type:
t2.medium
(4GB RAM)Security Group: Allow ports 8080 (Jenkins), 22 (SSH)
1.2 Install Jenkins on EC2
sudo apt update -y
sudo apt install openjdk-11-jdk -y
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update -y
sudo apt install jenkins -y
sudo systemctl enable jenkins
sudo systemctl start jenkins
โ Verify Jenkins is running:
sudo systemctl status jenkins
๐น Step 2: Configure Jenkins Pipeline for Kubernetes Deployment
๐ Create a Jenkinsfile
in your GitLab/GitHub repository:
pipeline {
agent any
environment {
KUBECONFIG = credentials('k8s-config') // Load Kubernetes config
}
stages {
stage('Checkout Code') {
steps {
git branch: 'main', url: 'https://gitlab.com/your-repo/easyshop.git'
}
}
stage('Build & Push Docker Image') {
steps {
sh 'docker build -t easyshop:latest .'
sh 'docker push <your-dockerhub-username>/easyshop:latest'
}
}
stage('Deploy to Kubernetes') {
steps {
sh 'kubectl apply -f kubernetes/deployment.yaml'
sh 'kubectl apply -f kubernetes/service.yaml'
}
}
}
}
โ Run the Jenkins Pipeline to automate Kubernetes deployments!
2๏ธโฃ GitLab CI/CD for Kubernetes
๐น Step 1: Register a GitLab Runner on an EC2 Instance
sudo apt install -y gitlab-runner
gitlab-runner register --url https://gitlab.com/ --registration-token <your-token>
๐ Select:
Executor: docker
Image: ubuntu:latest
โ Verify Runner Status:
gitlab-runner verify
๐น Step 2: Define GitLab CI/CD Pipeline
๐ Create .gitlab-ci.yml
in your repository:
stages:
- build
- deploy
build:
stage: build
script:
- docker build -t <your-dockerhub-username>/easyshop:latest .
- docker push <your-dockerhub-username>/easyshop:latest
deploy:
stage: deploy
script:
- kubectl apply -f kubernetes/deployment.yaml
- kubectl apply -f kubernetes/service.yaml
โ Commit & Push to trigger GitLab CI/CD pipeline!
3๏ธโฃ AWS CodePipeline for Kubernetes Deployments
๐น Step 1: Create an AWS EKS Cluster
eksctl create cluster --name easyshop-cluster --region us-east-1
โ Verify Cluster:
aws eks list-clusters
๐น Step 2: Create an AWS CodePipeline
๐ Define CodePipeline configuration in codepipeline.yaml
:
Resources:
CodePipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: easyshop-codepipeline
RoleArn: arn:aws:iam::123456789012:role/CodePipelineRole
Stages:
- Name: Source
Actions:
- Name: GitSource
ActionTypeId:
Category: Source
Owner: AWS
Provider: CodeCommit
Version: 1
Configuration:
RepositoryName: easyshop
BranchName: main
- Name: Deploy
Actions:
- Name: DeployToEKS
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CodeBuild
Version: 1
Configuration:
ProjectName: easyshop-k8s-deployment
โ Deploy CodePipeline:
aws cloudformation create-stack --stack-name easyshop-ci-cd --template-body file://codepipeline.yaml --capabilities CAPABILITY_NAMED_IAM
4๏ธโฃ Azure DevOps Pipeline for Kubernetes Deployments
๐น Step 1: Create an Azure AKS Cluster
az aks create --resource-group EasyShopRG --name easyshop-aks --node-count 2 --enable-addons monitoring --generate-ssh-keys
โ Get AKS Credentials:
az aks get-credentials --resource-group EasyShopRG --name easyshop-aks
๐น Step 2: Create an Azure DevOps Pipeline
๐ Define .azure-pipelines.yml
in your repository:
trigger:
branches:
include:
- main
stages:
- stage: Build
jobs:
- job: Build
steps:
- task: Docker@2
inputs:
command: build
repository: 'easyshop'
Dockerfile: 'Dockerfile'
tags: latest
- task: Docker@2
inputs:
command: push
repository: 'easyshop'
tags: latest
- stage: Deploy
jobs:
- job: Deploy
steps:
- task: KubernetesManifest@0
inputs:
action: deploy
namespace: 'default'
manifests: |
kubernetes/deployment.yaml
kubernetes/service.yaml
โ Commit & Push to trigger Azure DevOps pipeline!
5๏ธโฃ Multi-Cloud CI/CD Best Practices & Troubleshooting
๐น Best Practices
โ
Use GitHub/GitLab webhooks to trigger Jenkins builds
โ
Store Kubernetes credentials securely in CI/CD tools
โ
Implement Rolling Deployments in Kubernetes
๐น Common Issues & Fixes
๐ AWS CodePipeline Deployment Fails?
โ๏ธ Ensure Kubernetes credentials are loaded:
aws eks update-kubeconfig --name easyshop-cluster
๐ Azure DevOps Pipeline Not Deploying?
โ๏ธ Check pipeline logs in Azure DevOps:
az pipelines runs list
๐ฏ Conclusion
๐ Multi-Cloud CI/CD Automation is now fully implemented!
โ
Jenkins & GitLab deploy applications automatically
โ
AWS CodePipeline deploys workloads to EKS
โ
Azure DevOps Pipelines deploy to AKS
โ
Full Kubernetes deployment automation with zero manual intervention! ๐
This completes the end-to-end Kubernetes CI/CD automation setup! ๐
Subscribe to my newsletter
Read articles from Vikas Surve directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Vikas Surve
Vikas Surve
I am an ๐ ๐ฆ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฒ๐ฑ ๐๐ฒ๐๐ข๐ฝ๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ ๐๐ ๐ฝ๐ฒ๐ฟ๐ and ๐๐๐๐ฟ๐ฒ ๐๐ฑ๐บ๐ถ๐ป๐ถ๐๐๐ฟ๐ฎ๐๐ผ๐ฟ ๐๐๐๐ผ๐ฐ๐ถ๐ฎ๐๐ฒ with over ๐ญ๐ฌ ๐๐ฒ๐ฎ๐ฟ๐ ๐ผ๐ณ ๐ฒ๐ ๐ฝ๐ฒ๐ฟ๐ถ๐ฒ๐ป๐ฐ๐ฒ in designing, implementing, and optimizing DevOps solutions. My expertise includes ๐๐/๐๐ ๐ฎ๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป ๐๐๐ถ๐ป๐ด ๐๐ถ๐๐๐ฎ๐ฏ, ๐๐ฒ๐ป๐ธ๐ถ๐ป๐, ๐ฎ๐ป๐ฑ ๐๐๐๐ฟ๐ฒ ๐๐ฒ๐๐ข๐ฝ๐, as well as ๐๐ผ๐ป๐๐ฎ๐ถ๐ป๐ฒ๐ฟ ๐ผ๐ฟ๐ฐ๐ต๐ฒ๐๐๐ฟ๐ฎ๐๐ถ๐ผ๐ป ๐๐ถ๐๐ต ๐๐ผ๐ฐ๐ธ๐ฒ๐ฟ ๐ฎ๐ป๐ฑ ๐๐๐ฏ๐ฒ๐ฟ๐ป๐ฒ๐๐ฒ๐. ๐น ๐๐ ๐ฝ๐ฒ๐ฟ๐ ๐ถ๐ป ๐ฑ๐ฒ๐๐ถ๐ด๐ป๐ถ๐ป๐ด ๐ฎ๐ป๐ฑ ๐บ๐ฎ๐ป๐ฎ๐ด๐ถ๐ป๐ด ๐ฒ๐ป๐ฑ-๐๐ผ-๐ฒ๐ป๐ฑ ๐๐/๐๐ ๐ฝ๐ถ๐ฝ๐ฒ๐น๐ถ๐ป๐ฒ๐ ๐น ๐๐ฎ๐ป๐ฑ๐-๐ผ๐ป ๐ฒ๐ ๐ฝ๐ฒ๐ฟ๐ถ๐ฒ๐ป๐ฐ๐ฒ ๐๐ถ๐๐ต ๐๐๐๐ฟ๐ฒ, ๐๐๐ฏ๐ฒ๐ฟ๐ป๐ฒ๐๐ฒ๐ (๐๐๐ฆ), ๐ฎ๐ป๐ฑ ๐ง๐ฒ๐ฟ๐ฟ๐ฎ๐ณ๐ผ๐ฟ๐บ ๐ณ๐ผ๐ฟ ๐๐ฐ๐ฎ๐น๐ฎ๐ฏ๐น๐ฒ ๐ฑ๐ฒ๐ฝ๐น๐ผ๐๐บ๐ฒ๐ป๐๐ ๐น ๐ฃ๐ฎ๐๐๐ถ๐ผ๐ป๐ฎ๐๐ฒ ๐ฎ๐ฏ๐ผ๐๐ ๐ฎ๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป, ๐๐ฒ๐ฐ๐๐ฟ๐ถ๐๐, ๐ฎ๐ป๐ฑ ๐ฐ๐น๐ผ๐๐ฑ-๐ป๐ฎ๐๐ถ๐๐ฒ ๐๐ฒ๐ฐ๐ต๐ป๐ผ๐น๐ผ๐ด๐ถ๐ฒ๐ ๐ ๐ฆ๐ธ๐ถ๐น๐น๐ & ๐ง๐ผ๐ผ๐น๐ โ ๐๐ฒ๐๐ข๐ฝ๐ & ๐๐/๐๐: Azure DevOps, GitLab, Jenkins โ ๐๐น๐ผ๐๐ฑ & ๐๐ป๐ณ๐ฟ๐ฎ๐๐๐ฟ๐๐ฐ๐๐๐ฟ๐ฒ: Azure, AWS โ ๐๐ป๐ณ๐ฟ๐ฎ๐๐๐ฟ๐๐ฐ๐๐๐ฟ๐ฒ ๐ฎ๐ ๐๐ผ๐ฑ๐ฒ (๐๐ฎ๐): Terraform, Bicep โ ๐๐ผ๐ป๐๐ฎ๐ถ๐ป๐ฒ๐ฟ๐ & ๐ข๐ฟ๐ฐ๐ต๐ฒ๐๐๐ฟ๐ฎ๐๐ถ๐ผ๐ป: Docker, Kubernetes (AKS) โ ๐๐ผ๐ป๐ณ๐ถ๐ด ๐ ๐ฎ๐ป๐ฎ๐ด๐ฒ๐บ๐ฒ๐ป๐: PowerShell, Shell Scripting โ ๐ ๐ผ๐ป๐ถ๐๐ผ๐ฟ๐ถ๐ป๐ด & ๐ข๐ฏ๐๐ฒ๐ฟ๐๐ฎ๐ฏ๐ถ๐น๐ถ๐๐: Grafana, Prometheus, Azure Monitor โ ๐ฆ๐ฒ๐ฐ๐๐ฟ๐ถ๐๐ & ๐ก๐ฒ๐๐๐ผ๐ฟ๐ธ๐ถ๐ป๐ด: Load Balancers, Firewalls, ClusterIP โ ๐ข๐ฝ๐ฒ๐ฟ๐ฎ๐๐ถ๐ป๐ด ๐ฆ๐๐๐๐ฒ๐บ๐: Linux, Mac ๐ก ๐๐ฒ๐ ๐ฆ๐๐ฟ๐ฒ๐ป๐ด๐๐ต๐ โ ๐๐น๐ผ๐๐ฑ ๐๐ฟ๐ฐ๐ต๐ถ๐๐ฒ๐ฐ๐๐๐ฟ๐ฒ & ๐๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป โ Designing and managing scalable cloud solutions โ ๐๐/๐๐ & ๐๐ฒ๐๐ข๐ฝ๐ ๐๐ฒ๐ฎ๐ฑ๐ฒ๐ฟ๐๐ต๐ถ๐ฝ โ Implementing robust and automated software delivery pipelines โ ๐ง๐ฒ๐ฎ๐บ ๐๐ฒ๐ฎ๐ฑ๐ฒ๐ฟ๐๐ต๐ถ๐ฝ & ๐ ๐ฒ๐ป๐๐ผ๐ฟ๐๐ต๐ถ๐ฝ โ Leading a 5-member team, fostering collaboration and growth โ ๐ฆ๐ฒ๐ฐ๐๐ฟ๐ถ๐๐ & ๐๐ผ๐บ๐ฝ๐น๐ถ๐ฎ๐ป๐ฐ๐ฒ โ Ensuring cloud security, compliance, and best practices โ ๐ฃ๐ฟ๐ผ๐ฏ๐น๐ฒ๐บ ๐ฆ๐ผ๐น๐๐ถ๐ป๐ด & ๐ข๐ฝ๐๐ถ๐บ๐ถ๐๐ฎ๐๐ถ๐ผ๐ป โ Driving efficiency through automation and DevOps practices โ ๐๐ผ๐ป๐๐ถ๐ป๐๐ผ๐๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด & ๐๐ป๐ป๐ผ๐๐ฎ๐๐ถ๐ผ๐ป โ Exploring emerging technologies and best practices