Hands on DevSecOps Coaching that is provided on AWS and Azure Cloud platforms. Contact Coach AK at devops.coaching@gmail.com for more info. You can also reach out to Coach AK at +1(469) 733-5248
We will learn how to automate Docker builds using Jenkins and Deploy into Kubernetes Cluster in AWS Cloud. We will use kubectl command to deploy Docker images into EKS cluster. We will use Python based application. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following:
- Automating builds using Jenkins - Automating Docker image creation - Automating Docker image upload into Elastic container registry - Automating Deployments to Kubernetes Cluster using kubectl CLI plug-in
Pre-requisites: 1. EKS Cluster is setup and running. Click here to learn how to create EKS cluster.
We will learn how to create CICD pipeline to deploy springboot microservices using Jenkins pipeline into EKS Cluster with help of Kubernetes CLI plug-in.
We will use Springboot Microservices based Java application. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following:
- Automating builds using Jenkins Pipeline - Automating Docker image creation and tagging - Automating Docker image upload into AWS ECR - Automating Docker Containers Deployments to Kubernetes Cluster
Step # 1 - Create Maven3 variable under Global tool configuration in Jenkins
Make sure you create Maven3 variable under Global tool configuration.
Step #2 - Create Credentials for connecting to Kubernetes Cluster using kubeconfig
Click on Add Credentials, use Kubernetes configuration from drop down.
use secret file from drop down.
execute the below command to login as jenkins user.
sudo su - jenkins
you should see the nodes running in EKS cluster.
kubectl get nodes
Create namespace to deploy the containers
kubectl create namespace springboot-app-ns
kubectl get ns
Execute the below command to get kubeconfig info, copy the entire content of the file:
cat /var/lib/jenkins/.kube/config
Open your text editor or notepad, copy and paste the entire content and save in a file.
We will upload this file.
Enter ID as K8S and choose File and upload the file and save.
Enter ID as K8S and choose enter directly and paste the above file content and save.
Step # 3 - Create a pipeline in Jenkins
Create a new pipeline job.
Step # 4 - Copy the pipeline code from below Make sure you change red highlighted values below as per your settings: Your docker user id should be updated. your registry credentials ID from Jenkins from step # 1 should be copied
Azure Kubernetes Service (AKS) is a managed container orchestration service, based on the open source Kubernetes system, which is available on the Microsoft Azure public cloud. AKS allows you to quickly deploy a production ready Kubernetes cluster in Azure, deploy and manage containerized applications more easily with a fully managed Kubernetes service. We will see how to create AKS cluster in Azure cloud using Terraform.
AKS cluster can be created by many ways as mentioned below:
Creating an AKS resource with Terraform is incredibly easy, it only requires a single resource azurerm_kubernetes_cluster and in this post, we are going to walk through the necessary steps to create this with Terraform. We will create ACR and create a role with ACRpull assignment as well
Once the deployment is created, use kubectl to check on the deployments by running this command:
kubectl get deployments
To see the list of pods
kubectl get pods
Perform cleanup by deleting the AKS cluster
To avoid Azure charges, you should clean up unneeded resources. When the cluster is no longer needed, use terraform destroy command to remove the resource group, AKS cluster service, and all related resources.
We are going to learn how to Automate build and deploy of Springboot Microservices App into Azure Kubernetes Cluster(AKS) using Helm and Jenkins pipeline.
Sample springboot App Code:
I have created a sample Springboot App setup in GitHub. Click here to access code base in GitHub.
Jenkins pipeline will:
- Automate maven build(jar) using Jenkins - Automate Docker image creation - Automate Docker image upload into Azure container registry - Automate Springboot docker container Deployments to Azure Kubernetes Cluster using Helm charts
sh "helm upgrade first --install mychart --namespace helm-deployment --set image.tag=$BUILD_NUMBER"
}
}
}
}
}
Step # 5 - Build the pipeline
Step # 6 - Verify deployments in AKS
Execute the below command to list the helm deployments:
helm ls -n helm-deployment
kubectl get pods -n helm-deployment
kubectl get services -n helm-deployment
Steps # 7 - Access Springboot App Deployed in AKS cluster
Once deployment is successful, go to browser and enter above load balancer URL mentioned above
You should see page like below:
Clean up the Cluster:
To avoid charges from Azure, you should clean up unneeded resources, use az group delete command to remove the resource group, and all related resources in that group.
az group delete --name resource-group-name --yes --no-wait