We
will learn how to automate Docker builds using Jenkins and Deploy into
Kubernetes Cluster(AKS) in Azure Cloud. We will use kubectl command to deploy Docker images into AKS 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 Docker registry
- Automating Deployments to Kubernetes Cluster using kubectl CLI plug-in
Pre-requistes:
1. AKS Cluster is setup and running. Click here to learn how to create AKS cluster.
1. AKS Cluster is setup and running. Click here to learn how to create AKS cluster.
2. Jenkins Master is up and running.
3. Docker, Docker pipeline and Kubectl CLI plug-ins are installed in Jenkins
3. Docker, Docker pipeline and Kubectl CLI plug-ins are installed in Jenkins
Step #1 - Create Credentials for Acure Container Registry
Go to Jenkins UI, click on Credentials -->
Click on Global credentials
Now Create an entry for connecting to ACR. Make sure you enter the ID as ACR
Step #3 - Create Credentials entry for AKS Cluster
Click on Global credentials
Click on Add Credentials
Now Create an entry for connecting to ACR. Make sure you enter the ID as ACR
Click on Add Credentials, use Kubernetes configuration from drop down.
execute the below command to get kubeconfig info, copy the entire content of the file:
sudo cat ~/.kube/config
Enter ID as K8S and choose enter directly and paste the above file content and save.
Step # 4 - Create a pipeline in Jenkins
Step # 5 - Copy the pipeline code from below
Make sure you change red highlighted values below:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied
Make sure you change red highlighted values below:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied
Step # 6 - Build the pipeline
Once you create the pipeline and changes values per your Docker user id and credentials ID, click on
Step # 7 - Verify deployments to K8S
kubectl get pods
kubectl get deployments
Steps # 8 - Access Python App in K8S cluster
Once build is successful, go to browser and enter master or worker node public ip address along with port number mentioned above
http://master_or_worker_node_public_ipaddress:port_no_from_above
You should see page like below:
Please watch the above steps in YouTube channel:
No comments:
Post a Comment