This project is a demonstration of Fully automated End-to-End DevOps workflow for deploying and managing a cloud-native application using a variety of tools and technologies including GitHub, Terraform, AWS, Ansible, Jenkins, Maven, Trivy, Docker,Cri-o and Kubernetes.
Before getting started, ensure you have the following installed:
-
Install Terraform and AWS CLI and configure it on your local machine
-
Navigate to Project Directory and enter the command
terraform init
for terraform initialization
- Apply Terraform configuration:terraform apply --auto-approve
3.Connect to Masternode via ssh and enter this command for admin passwordsudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Access Jenkins through web browser and set it up.
- Establish passwordless connection between 'Master-Server' & 'Node-Server'
```
<Commands to run in 'Node-Server'>
sudo su -
passwd ubuntu # (set password)
vi /etc/ssh/sshd_config # (Allow 'PermitRootLogin yes' & allow 'PasswordAuthentication yes')
service sshd restart
<Commands to run in 'Master-Server'>
ssh-keygen # (this will generate ssh key, press enter when prompted)
ssh-copy-id ubuntu@<Node_Private_IP> # (enter 'yes' when prompted & enter the Node's ubuntu password when prompted)
```
- Note : if permission denied when copying ssh-id ,then copy the public key from
.ssh/id_rsa.pub
and login in to Node-server and navigate the directory.ssh/authorized_keys
and save the public key here, corresponding private key needed for jenkins Credentials while remote login to node server
- Access Jenkins portal & add credentials in Jenkins portal as below:
(Manage Jenkins --> Credentials --> System --> Global credentials) a. Dockerhub credentials - username & password (Use 'secret text' & save them separately) b. K8s server username with private key (Use 'SSH Username with private key') c. Add Github username & token (Generate Github token & save as 'secret key' in Jenkins server) (Github: Github settings --> Developer settings --> Personal Token classic --> Generate) d. Dockerhub token (optional) (Generate token & save as 'secret key') (Dockerhub: Account --> Settings --> Security --> Generate token & copy it)
- Add required plugins in Jenkins portal
```
(Manage Jenkins --> Plugins --> Available plugins --> 'ssh agent' --> Install)
(This plugin is required to generate ssh agent syntax using pipeline syntax generator)
```
5. Create Pipeline Job:
- Configure Jenkins pipeline to:
- Perform Maven build from the master server.
- Build Docker image and push to Docker Hub.
- Image Scanning by trivy
- Deploy the application to the Kubernetes node via SSH agent.
- Apply Kubernetes manifest files.
- Expose the application via NodePort for access.
- Run the pipeline
6. Accessing the Application:
- Once the deployment is successful, obtain the output to access the application.
- Access the application using the NodePort
- Check the pods are running properly From Node server
- Automate the pipeline if any changes are pushed to Github
```
(Webhook will be created in Github & trigger will be created in Jenkins)
Jenkins --> Configure --> Build triggers --> 'Github hook trigger for GitSCM polling' --> Save
Jenkins --> <Your_Account> --> Configure --> API Tokens --> <Jenkins-API-Token>
Github --> <Your-Repo> --> Settings --> Webhooks --> "<Jenkins-url>:8080/github-webhook/"; -->
Content type: json; Secret: <Jenkins-API-Token> --> Add Webhook
(Try making any changes in your code & the pipeline should automatically trigger)
```
- terraform destroy
In summary, this project showcases a streamlined DevOps workflow utilizing leading tools like GitHub, Terraform, AWS, Ansible, Jenkins, Maven, Trivy, Docker, and Kubernetes. By automating infrastructure setup, CI/CD pipelines, and Kubernetes deployments, we've demonstrated efficiency and scalability in cloud-native application management.
Embracing automation and best practices in DevOps fosters rapid delivery and high-quality software. This project serves as a foundation for teams to enhance collaboration, productivity, and innovation in their software delivery pipelines. Continued customization and optimization ensure ongoing success in DevOps endeavors.