How Google Uses Jenkins & Kubernetes for Fully Automated CI/CD
This article explains how Jenkins and Kubernetes can be integrated to build a fully automated CI/CD pipeline, using Google’s real‑world implementation as a step‑by‑step example that covers installation, configuration, pipeline scripting, Docker image handling, and Kubernetes deployment.
Introduction
CI/CD pipelines combine Jenkins and Kubernetes to automate building, testing, and deploying containerized applications.
Key Concepts
Jenkins
Open‑source automation server; pipelines defined in a Jenkinsfile; extensible via plugins (e.g., Kubernetes plugin).
Kubernetes
Container orchestration platform that runs pods, manages scaling, service discovery, and rolling updates.
Integrating Jenkins with Kubernetes
Install and configure the Kubernetes plugin
On the Jenkins master, install the “Kubernetes” plugin. In Manage Jenkins → Configure System → Cloud → Kubernetes provide the cluster API server URL, service‑account token or credentials, and the namespace where build agents will be created.
Configure the Kubernetes cloud
Define pod templates that specify the Docker image for the build container, resource limits, and any required volumes. Jenkins will launch a pod per build, execute the pipeline steps, then terminate the pod.
Typical Build Flow
Jenkins detects a commit in the source‑control repository (e.g., Git).
The pipeline checks out the code.
A Docker image is built and tagged with ${env.BUILD_NUMBER}.
The image is pushed to a container registry (Google Container Registry in the example).
Kubernetes deploys the new image using the supplied manifests.
Example: Google‑Scale CI/CD Pipeline
Jenkinsfile
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build and Push Docker Image') {
steps {
script {
def image = docker.build("gcr.io/project-id/app-name:${env.BUILD_NUMBER}")
docker.withRegistry('https://gcr.io', 'gcr-credentials') {
image.push()
}
}
}
}
stage('Deploy to Kubernetes') {
steps {
script {
kubernetesDeploy(
kubeconfigId: 'kubeconfig',
configs: 'k8s/*.yaml'
)
}
}
}
}
}Kubernetes Deployment Manifests
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-deployment
spec:
replicas: 3
selector:
matchLabels:
app: app-name
template:
metadata:
labels:
app: app-name
spec:
containers:
- name: app-container
image: gcr.io/project-id/app-name:${env.BUILD_NUMBER}
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
selector:
app: app-name
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancerStep‑by‑Step Execution
Install plugins : Add the Kubernetes plugin and configure the cloud connection (API server URL, credentials, namespace).
Create Jenkinsfile : Include stages for checkout, Docker build/push, and Kubernetes deployment as shown above.
Provide manifests : Store the deployment and service YAML files in the repository under k8s/.
Trigger a build : Push a commit; Jenkins automatically starts the pipeline. Build logs and status are visible in the Jenkins UI or via webhook notifications.
Outcomes
The pipeline delivers fully automated delivery: developers push code, Jenkins builds and publishes Docker images, and Kubernetes rolls out updates without manual intervention, reducing release cycle time and improving reliability.
Full-Stack DevOps & Kubernetes
Focused on sharing DevOps, Kubernetes, Linux, Docker, Istio, microservices, Spring Cloud, Python, Go, databases, Nginx, Tomcat, cloud computing, and related technologies.
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.
