KUBERNETES
Kubernetes has become the preferred platform of choice for container orchestration and deliver maximum operational efficiency. To understand how K8s works, one must understand its most basic execution unit – a pod.
Kubernetes doesn’t run containers directly, rather through a higher-level structure called a pod. A pod has an application’s container (or, in some cases, multiple containers), storage resources, a unique network IP, and options that govern how the container(s) should run.
Pods can hold multiple containers or just one. Every container in a pod will share the same resources and network. A pod is used as a replication unit in Kubernetes; hence, it is advisable to not add too many containers in one pod. Future scaling up would lead to unnecessary and expensive duplication.
To maximize the ease and speed of Kubernetes, DevOps teams like to add automation using Jenkins CI/CD pipelines. Not only does this make the entire process of building, testing, and deploying software go faster, but it also minimizes human error. Here is how Jenkins CI/CD pipeline is used to deploy a spring boot application in K8s.
Create a Jenkins pipeline to dockerize a spring application, build docker image, push it to the dockerhub repo and then pull the image into an AKS cluster to run it in a pod.
All the files required for this task are available in this repository:
https://github.com/saiachyuth5/simple-spring
A spring-boot application, dockerfile to containerize the application.
STEPS:
1. Install Jenkins :
2. Connect host docker daemon to Jenkins:
3. Adding global credentials:
4. Create the Jenkinsfile :
Jenkinsfile:
NOTE: While this example uses actual id to login to Azure, its recommended to use credentials to avoid using exact parameters.
pipeline {
environment {
registryCredential = "docker"
}
agent any
stages {
stage(‘Build’) {
steps{
script {
sh 'mvn clean install'
}
}
}
stage(‘Load’) {
steps{
script {
app = docker.build("cloud007/simple-spring")
}
}
}
stage(‘Deploy’) {
steps{
script {
docker.withRegistry( "https://registry.hub.docker.com", registryCredential ) {
// dockerImage.push()
app.push("latest")
}
}
}
}
stage('Deploy to ACS'){
steps{
withCredentials([azureServicePrincipal('dbb6d63b-41ab-4e71-b9ed-32b3be06eeb8')]) {
sh 'echo "logging in" '
sh 'az login --service-principal -u **************************** -p ********************************* -t **********************************’
sh 'az account set -s ****************************'
sh 'az aks get-credentials --resource-group ilink --name mycluster'
sh 'kubectl apply -f sample.yaml'
}
}
}
}
}
5. Create the Jenkins project:
6. Create and connect to Azure Kubernetes cluster:
YAML used:
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-helloworld
spec:
replicas: 1
selector:
matchLabels:
app: spring-helloworld
template:
metadata:
labels:
app: spring-helloworld
spec:
containers:
- name: spring-helloworld
image: cloud007/simple-spring:latest
imagePullPolicy: Always
ports:
- containerPort: 80
Here are some common problems faced during this process and the troubleshooting procedure.
In an upcoming article we will show you how to deploy a pod containing three applications using Jenkins ci/cd pipeline and update them selectively.
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.