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:
CloudIQ is a leading Cloud Consulting and Solutions firm that helps businesses solve today’s problems and plan the enterprise of tomorrow by integrating intelligent cloud solutions. We help you leverage the technologies that make your people more productive, your infrastructure more intelligent, and your business more profitable.
LATEST THINKING
INDIA
Chennai One IT SEZ,
Module No:5-C, Phase ll, 2nd Floor, North Block, Pallavaram-Thoraipakkam 200 ft road, Thoraipakkam, Chennai – 600097
© 2023 CloudIQ Technologies. All rights reserved.
Get in touch
Please contact us using the form below
USA
INDIA