A complete CI/CD project to build and publish an application by Jenkins to the Kubernetes cluster.
Follow aws branch for AWS cloud deployment steps.
Initially, configure a Kubernetes cluster with 1 master node, 1 worker node and a Jenkins server with Docker and Kubectl setup by Ansible playbook. Then automate build and publish of a Java application with MySQL database in Kubernetes cluster using CI/CD pipeline.
Prepare three virtual machines in RHEL 9 equivalent environment. One of them is for the Kubernetes master node, another one is for the worker node and the third is for the Jenkins server.
Follow this kubernetes-cluster-setup-playbook to setup Kubernetes cluster by running an Ansible playbook.
Follow this jenkins-docker-setup-playbook to install Jenkins server, Docker, Kubectl by running an Ansible playbook.
Install Plugins:
- Docker
- Docker Pipeline
- Kubernetes
- Kubernetes CLI
Tools setup:
- JDK - Name:
Java_11
, JAVA_HOME:/usr/lib/jvm/java-11-openjdk
- Git - Name:
Git
, Path executable:/usr/bin/git
- Maven - Name:
Maven_3
, MAVEN_HOME:/usr/share/maven
- Docker - Name:
Docker_24
, Installation root:/usr/bin/
- Kind: 'Username with password', ID:
docker_credentials
, Username:<username>
, Password:<docker_access_token>
. - Kind: 'Secret file', ID:
kubeconfig
, File: select your kubeconfig.txt file.
- Create New Item > Enter name (kubernetes-deploy) > Select ‘Pipeline’ type.
- Goto ‘Your pipeline’ > Configure > Select Poll SCM > Set schedule
H/2 * * * *
> Select Pipeline script from SCM > Repository URL > Select your branch to build > Script Path (Jenkinsfile) > Save. - Goto ‘Your pipeline’ > Build Now.
Creating new commit in the repository will trigger a new build with following stages:
- Git Clone
- Build Artifact
- Build Container Image
- Publish Docker Image
- Deploy App in Kubernetes
- Visit http://worker-node-address from your local browser.
- Use username 'admin' and password 'admin' to login to the dashboard.