This repository contains the following components:
Simple Java Code Dockerfile Kubernetes manifests (deployment.yaml & service.yaml) Jenkinsfile (CI & CD) Terraform code
This project demonstrates setting up a CI/CD pipeline using Terraform, Jenkins, Docker, and Kubernetes.
Using Terraform, create two EC2 instances:
Master-Server
: Installed with Java, Jenkins, Maven, Docker, Ansible, and Trivy.Node-Server
: Installed with Docker, Kubeadm, and Kubernetes.
-
On Node-Server:
sudo su - passwd ec2-user # Set a password for ec2-user vi /etc/ssh/sshd_config # Enable 'PermitRootLogin yes' & 'PasswordAuthentication yes' service sshd restart
-
On Master-Server:
On Master-Server:
ssh-keygen # Generate SSH key, press enter when prompted ssh-copy-id ec2-user@<Node_Private_IP> # Enter 'yes' and then ec2-user's password when prompted
- Add Credentials in Jenkins Dockerhub credentials (username & password). Kubernetes (K8s) server username with private key. GitHub username & token. Dockerhub token (optional).
Install the 'ssh agent' plugin in Jenkins for SSH connection management.
CI-pipeline: Set up and run the Continuous Integration pipeline. CD-pipeline: Set up and run the Continuous Deployment pipeline.
Access the deployed application via http://<Node_Server_Public_IP>:<NodePort_No>.
Automate the CD pipeline to run after the CI pipeline is successful. Set up GitHub webhooks to trigger the CI pipeline on code changes.
To destroy the entire infrastructure created by Terraform, use the following command:
bash Copy code terraform destroy --auto-approve