Skip to content

Automated DevOps workflow for deploying java application using Jenkins, Kubernetes, Docker,Maven,Terraform

Notifications You must be signed in to change notification settings

safuvanh/DevOps_Main_Project-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevOps Real-World Automated Project

Overview

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.

444

Prerequisites

Before getting started, ensure you have the following installed:

Steps:

  1. Install Terraform and AWS CLI and configure it on your local machine

    Screenshot (372)

  2. Navigate to Project Directory and enter the command terraform init for terraform initialization

    Screenshot (435)

    - Apply Terraform configuration: terraform apply --auto-approve

    Screenshot (436)

    Screenshot (437)

    3.Connect to Masternode via ssh and enter this command for admin password

    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    

- Access Jenkins through web browser and set it up.

Screenshot (439)

- 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

    Screenshot (443)
  1. 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)
    
    
    Screenshot (444)

- 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)
```

Screenshot (445)
5. Create Pipeline Job:

Screenshot (446)

- 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.

Screenshot (450)

- Run the pipeline

Screenshot (448)

Screenshot (449)
6. Accessing the Application:

- Once the deployment is successful, obtain the output to access the application.
- Access the application using the NodePort

Screenshot (452)

Screenshot (453)

- Check the pods are running properly From Node server

image

- 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)
   ```

Screenshot (456)

Screenshot (457)

Destroy all

- terraform destroy

Screenshot (458)

Conclusion

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.

About

Automated DevOps workflow for deploying java application using Jenkins, Kubernetes, Docker,Maven,Terraform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published