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
Let us learn how to configure a self-hosted agent using Docker in Azure DevOps pipelines.
What is an Agent?
An agent is computing infrastructure with installed agent software that runs one job at a time.To build your code or deploy your software using Azure Pipelines, you need at least one agent. As you add more code and people, you'll eventually need more.
When your pipeline runs, the system begins one or more jobs.
In Azure pipelines, there are two types of build agents:
Microsoft-hosted agents - This is a service totally managed by Microsoft and it's cleared on every execution of the pipeline (on each pipeline execution, you have a fresh new environment).
Self-hosted agents - This is a service that you can to set up and manage by yourself. This can be a custom virtual machine on Azure or a custom on-premise machine inside your infrastructure. In a self-hosted agent, you can install all the software you need for your builds, and this is persisted on every pipeline execution. A self-hosted agent can be on Windows, Linux, macOS, or in a Docker container.
You can set up a self-hosted agent in Azure Pipelines to run inside a Windows Server Core (for Windows hosts), or Ubuntu container (for Linux hosts) with Docker.We will learn in this article on how to host Ubuntu Docker container on Linux machines.
Let us learn how to create and configure a Self-Hosted Agent in Azure DevOps (ADO).
What is an Agent?
An agent is computing infrastructure with installed agent software that runs one job at a time.
To build your code or deploy your software using Azure Pipelines, you need at least one agent. As you add more code and people, you'll eventually need more.
When your pipeline runs, the system begins one or more jobs.
In Azure pipelines, there are two types of build agents:
Microsoft-hosted agents - This is a service totally managed by Microsoft and it's cleared on every execution of the pipeline (on each pipeline execution, you have a fresh new environment).
Self-hosted agents - This is a service that you can to set up and manage by yourself. This can be a custom virtual machine on Azure or a custom on-premise machine inside your infrastructure. In a self-hosted agent, you can install all the software you need for your builds, and this is persisted on every pipeline execution. A self-hosted agent can be on Windows, Linux, macOS, or in a Docker container.
Accept the Team Explorer Everywhere license agreement now?
Type Y and enter
Step #5:
Enter server URL > https://dev.azure.com/yourorganization
Step #6:
Enter authentication type (press enter for PAT) > PAT
Step #7:
Enter personal access token, generated from this step
Step #8:
Enter Agent pool
Give some name
Step #9:
Enter Agent name --> myBuildAgent_1
Step #10:
Enter work folder > enter
that's it agent is successfully configured.
Configure the Agent to run as a Service
sudo ./svc.sh install &
Execute now to run as a service
./runsvc.sh &
Check the status of build Agent
Click on Ubuntu-18-VM pool name
Click on Agents
This confirms that Build agent is successfully configured in Azure DevOps and is available to run builds.
Steps for removing Agent from the agent pool
Remove the service first
sudo ./svc.sh uninstall
./config.sh remove
To Perform Java related builds on this Agent, make sure you install Java and Maven on this VM.
Install Java 11
sudo apt-get install default-jdk -y
Maven Installation Maven is a popular build tool used for building Java applications. Please click here to learn more about Maven. You can install Maven by executing below command: