5 Step CI/CD In Kubernetes using Artifactory, Jenkins & Helm
Contents
- Setup Kubernetes Cluster on EKS
- Setup Kubernetes Cluster on GKE
- Setup Kubernetes Cluster on AKS
- Install Artifactory on kubernetes
- Install Jenkins on kubernetes
- Configure Continuous Integration/Continuous Deployment
Prerequisites
- Basic knowledge of Docker, Jenkins, Kubernetes and Artifactory
Setup Kubernetes Cluster on EKS
Follow this to setup kubernetes cluster on EKS. https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html
Setup Kubernetes Cluster on GKE
Follow this to setup kubernetes cluster on GKE. https://cloud.google.com/container-engine/docs/quickstart
Setup Kubernetes Cluster on AKS
Follow this to setup kubernetes cluster on AKS. https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-deploy-cluster
Install Artifactory on kubernetes
Here is documentation to install JFrog Artifactory on kubernetes artifactory-docker-examples
Here is link to official helm chart for Artifactory https://github.com/kubernetes/charts/tree/master/stable/artifactory
Note If you are using Artifactory SaaS you can skip this step.
Configure docker insecure registry in each node of kubernetes cluster if you are using self-signed certificate.
-
Get cluster ip of nginx services by running following command:
kubectl get services nginx-kubernetes-service
-
Ssh into each node of cluster and configure insecure registry using steps provided here
Note: configure range which include
$CLUSTER_IP
as insecure registry. -
Add following entry in
/etc/hosts
file:$CLUSTER_IP docker.artifactory docker-remote.artifactory docker-local.artifactory
-
Pull
node
docker image from artifactory by running following command:docker pull docker.artifactory/node
Install Jenkins on kubernetes
Use Helm Chart to install jenkins in kubernetes.
Note: Make sure to increase resources for Jenkins deployment in values.yaml file. Jenkins comes with the Kubernetes plugin..
Cache docker images of jenkins master and agent in Artifactory by changing value of Master.Image
to docker.artifactory/jenkinsci/jenkins
and Agent.Image
to docker.artifactory/jenkinsci/jnlp-slave
in values.yaml file.
Configuring Jenkins to build docker images:
- From Jenkins home click on Manage Jenkins -> Configure System.
- You will see section Cloud -> Kubernetes -> Images -> Volumes.
- Click on Add Volume and add Host Path Volume with following mount path:
- ssh into each kubernetes node of your cluster and perform following:
- Create
jenkins
user. - Add
jenkins
user to docker group. - Make sure
jenkins
user can access/var/run/docker.sock
and/usr/bin/docker
in each kubernetes node. - Create
test
job in Jenkins and rundocker version
command fromtest
job.
- Create
5 Step CI/CD
Step 1. Create an application war file
- Creates a sample application called ‘webservice-1.1.2.war’
- Pushes it to a local repository in Artifactory
- gradle-example
Step 2. Create a template Docker image
- Creates a base Docker image called ‘docker-framework’ using Ubuntu + Java + Tomcat
- Pushes it to a local repository in Artifactory
- docker-framework
Step 3. Create a product Docker image
- Downloads, from Artifactory, the ‘webservice-1.1.2.war’ file and the ‘docker-framework’ Docker image, that were created in the previous two pipelines
- Creates a ‘docker-app’ production Docker image
- Pushes it to Artifactory
- Promotes it to a production repository in Artifactory
- docker-app
Step 4. Create Helm chart of product Docker image
- Create helm chart of
docker-app
- Push helm chart in local helm repository in Artifactory
- chart
docker-app
in Kubernetes cluster using helm chart
Step 5. Deploy - Pull helm chart from Virtual helm repository of Artifactory
- Deploy
docker-app
in Kubernetes using downloaded helm chart - deploy