CI/CD Pipeline
A Kubernetes pod - incidentally, some say it is named after a whale pod because the docker logo is a whale – is the foundational unit of execution in a K8s ecosystem. While docker is the most common container runtime, pods are container agnostic and support other containers as well.
Simply put, a K8s pod is a layer of abstraction wrapped around containers to group them together to allocate resources and to manage them efficiently.
Continuous integration and delivery or CI/CD is a critical part of DevOps ecosystems, especially for cloud-native applications. DevOps teams frequently use Jenkins CI/CD pipelines to increase the speed and quality of collaborated software development ecosystems by adding automation. Thanks to Helm, deploying Jenkins server to K8s is quick and easy. The difficult bit is building the pipeline.
Here is a post that describes how to deploy a pod containing three applications using a Jenkins CI/CD pipeline and update them selectively.
Use a Jenkins pipeline to build a spring-boot application to generate jar file, dockerize the application to create a docker image, push the image to a docker repository and pull the image into the pod to create containers. The pod should contain 3 containers for the three applications, respectively. Upon git commit, only the container for which there is a change must be updated (rolling update).
pipeline {
agent any
stages {
stage('Build1'){
steps{
dir('app1'){
script{
git 'https://github.com/cloud/simple-spring.git'
sh 'mvn clean install'
app = docker.build("cloud007/simple-spring")
docker.withRegistry( "https://registry.hub.docker.com", "dockerhub" ) {
// dockerImage.push()
app.push("latest")
}
}
}
}
}
stage('Build2'){
steps{
dir('app2'){
script{
git 'https://github.com/cloud/simple-spring-2.git'
sh 'mvn clean install'
app = docker.build("cloud007/simple-spring-2")
docker.withRegistry( "https://registry.hub.docker.com", "dockerhub" ) {
// dockerImage.push()
app.push("latest")
}
}
}
}
}
stage('Build3'){
steps{
dir('app3'){
script{
git 'https://github.com/cloud/simple-spring-3.git'
sh 'mvn clean install'
app = docker.build("cloud007/simple-spring-3")
docker.withRegistry( "https://registry.hub.docker.com", "dockerhub" ) {
// dockerImage.push()
app.push("latest")
}
}
}
}
}
stage('Orchestrate')
{
steps{
script{
sh 'kubectl apply -f demo.yaml'
}
}
}
}
}
4. Make sure to properly configure docker and expose the dockerd in port 4243 and then change permission to allow Jenkins to use docker commands by changing permission for the /var/run/docker.sock shown.
5. Coming to integrating Kubernetes with Jenkins, it can be done using two plugins:
Refer: https://github.com/jenkinsci/kubernetes-plugin
Refer: https://github.com/jenkinsci/kubernetes-cli-plugin/blob/master/README.md
Hence, we installed kubectl on the Jenkins host, configured the cluster manually, and ran shell commands from the Jenkins pipeline, where Jenkins was recognized as an anonymous user and was only granted get access but couldn’t create pods/deployments.
Here are some common problems faced during this process and the troubleshooting procedure.
Here are some suggested best practices
Share this:
In today's fast-paced enterprise world, the pressure is on to create workflows that are not just efficient, but truly intelligent and scalable. Gone are the days when clunky, form-based interfaces could keep up. They were rigid, often frustrating for users, and crucially, lacked the smarts needed to drive real productivity. But what if your forms […]
Are outdated HR processes holding your enterprise back? In today's hyper-competitive landscape, the efficiency of your human resources directly impacts your bottom line, employee satisfaction, and ability to attract top talent. Yet, many organizations are still grappling with manual, resource-intensive tasks that drain productivity and stifle growth. Imagine a world where: Crafting compelling job descriptions […]
In today's hyper-competitive digital landscape, delivering an exceptional user experience (UX) isn't just a nice-to-have – it's the bedrock of customer loyalty and business growth. But as customer behaviors constantly evolve and applications grow increasingly complex, a critical question emerges: How can organizations consistently measure, monitor, and elevate the user experience at scale, and in […]
Partner with CloudIQ to achieve immediate gains while building a strong foundation for long-term, transformative success.