Automate Kubernetes Deployments: Step‑by‑Step Jenkins Pipeline Guide
Learn how to connect Jenkins Pipeline with Kubernetes to automate building, testing, and deploying containerized applications, covering prerequisite setup, detailed pipeline stages—including code checkout, Docker image creation, testing, registry push, and Kubernetes deployment—complete with code snippets and configuration tips.
Introduction
Kubernetes is an open‑source container orchestration platform that helps development teams manage and deploy containerized applications. Jenkins is a popular continuous integration and continuous delivery tool that can automate building, testing, and deploying applications. This article explains how to connect Jenkins Pipeline with Kubernetes to achieve automated deployment of applications to a Kubernetes cluster.
Preparation
Before starting, complete the following preparations:
Install a Jenkins server.
Configure the Jenkins Kubernetes plugin.
Install Docker and Kubernetes.
Jenkins Pipeline and Kubernetes Integration Process
The following diagram illustrates the integration workflow between Jenkins Pipeline and Kubernetes.
Step Details
1. Checkout Code
In the first stage of the Jenkins Pipeline, checkout the source code from a version control system such as Git.
node {
stage('Checkout Code') {
git ''
}
}2. Build Docker Image
Build a Docker image using a Dockerfile that defines the build process.
stage('Build Docker Image') {
docker.build('my-app:latest', '.')
}3. Test Docker Image
After building the image, run tests (unit, integration, etc.) against the Docker image.
stage('Test Docker Image') {
sh 'docker run my-app:latest npm test'
}4. Push Docker Image to Registry
When tests pass, push the Docker image to a registry for later deployment.
stage('Push Docker Image to Registry') {
docker.withRegistry('https://your-registry', 'credentials-id') {
sh 'docker push my-app:latest'
}
}5. Deploy to Kubernetes
Finally, deploy the application to a Kubernetes cluster using the Kubernetes plugin.
stage('Deploy to Kubernetes') {
kubernetesDeploy(
configs: 'kubernetes/deployment.yaml',
kubeconfigId: 'your-kubeconfig-id',
kubeconfigFile: '',
enableConfigSubstitution: true
)
}The deployment.yaml file defines the Kubernetes deployment configuration and can be customized to suit the application's requirements.
Conclusion
By integrating Jenkins Pipeline with Kubernetes, you can automate the build, test, and deployment processes, greatly improving development team efficiency and ensuring consistency across environments.
This guide demonstrated a simple example of the integration workflow and provided corresponding code snippets to help you connect Jenkins with Kubernetes.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
