Having a Kubernetes cluster is half the battle. The other half is getting code into it — reliably, quickly, and automatically. We’re sharing our CI/CD pipeline with Jenkins, which has undergone a dramatic evolution over the past few months.
From Jenkins Freestyle to Pipeline-as-Code¶
Our old Jenkins jobs were freestyle projects — click-configured in the GUI. Unreliable, non-reproducible. Jenkins Pipeline changed that: the entire build process is a Groovy script in a Jenkinsfile, versioned directly in the project repository.
Jenkins on Kubernetes¶
Jenkins itself runs in the Kubernetes cluster. The Kubernetes plugin for Jenkins dynamically launches build agents as pods — each build gets a clean, isolated agent. No “polluted” build environments.
When there’s nothing to build, only the Jenkins master runs. Zero cost for idle agents. During peak load, the cluster automatically scales up.
Our Standard Jenkinsfile¶
pipeline {
agent {
kubernetes {
yaml |-
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.5-jdk-8
- name: docker
image: docker:17.06
}
}
stages {
stage('Build') {
steps { container('maven') { sh 'mvn clean package' } }
}
stage('Docker Build') {
steps {
container('docker') {
sh "docker build -t registry.core.cz/app:${BUILD_NUMBER} ."
sh "docker push registry.core.cz/app:${BUILD_NUMBER}"
}
}
}
stage('Deploy') {
steps {
sh "helm upgrade --install app ./chart --set image.tag=${BUILD_NUMBER}"
}
}
}
}
Deployment Strategy¶
For staging: automatic deploy after every successful build. For production: a manual approval step in the Jenkins Pipeline. Helm upgrade --install ensures a rolling update with zero downtime.
Rollback is simple: helm rollback release-name revision-number. Helm maintains a history of revisions.
What We Want to Improve¶
- Canary deployments — currently just rolling updates
- Automated smoke tests after deploy
- Image vulnerability scanning in the pipeline
- GitOps approach — deploy triggered by changes in Git
CI/CD Is the Key to Agile Kubernetes¶
Kubernetes without automated CI/CD is like a race car without fuel. Jenkins with Pipeline-as-Code and the Kubernetes plugin lets us deploy dozens of services daily with confidence.
Need help with implementation?
Our experts can help with design, implementation, and operations. From architecture to production.
Contact us