There are no items in your cart
Add More
Add More
Item Details | Price |
---|
Sun Apr 2, 2023
In this article, you will be able to learn that how to create scripts to install docker, minikube and sonarqube in EC2 Instance where we will be deploying our SpringBoot Application and deploy to Minikube and docker to build our images for our application and SonarQube to do our code quality checks and Trivy and Terrascan to scan Docker images and K8s yaml files.
Docker is a containerization platform that allows developers to package their applications and dependencies into lightweight, portable containers. This makes it easy to deploy and run applications on any system that supports Docker.
Minikube is a tool that allows you to run a single-node Kubernetes cluster locally on your development machine. This is useful for testing and developing Kubernetes-based applications without the need for a full-fledged cluster.
Kubectl is a command-line tool for controlling Kubernetes clusters. It allows you to deploy, inspect, and manage your applications on a Kubernetes cluster. You can use kubectl to create, update, and delete resources, such as pods, services, and deployments.
SonarQube is an open-source platform for continuous inspection of code quality. It provides a wide range of code analysis tools, including static code analysis, unit testing, and code coverage.
Trivy can scan for vulnerabilities in a wide range of package formats, including Alpine, Debian, Ubuntu, and Red Hat Enterprise Linux (RHEL) packages, as well as container images in the Docker, OCI, and JFrog formats. It supports multiple languages, such as Go, Java, Node.js, Ruby, and Python, and it can scan for vulnerabilities in both the operating system and application level.
Terrascan can scan for vulnerabilities in Terraform and CloudFormation files, and it uses a rule-based engine to detect and report on security risks and compliance issues, such as misconfigurations, insecure settings, and exposed secrets. The rule-base is continuously updated by the community and the Accurics team. It can be run as a command-line tool, and it can also be integrated with various CI/CD tools and container orchestration platforms, such as Jenkins, GitHub Actions, and Kubernetes.
Using Github Actions, you can automate the deployment of these three technologies by writing scripts that perform the necessary steps to set up each technology on a target machine. These scripts can be integrated into Github Actions workflows, which can be triggered by events such as a push to a specific branch.
Step by Step Process
In the DevOps Mini Project Series 5 , we have seen that EC2 Instance is been created by Terraform and in that EC2 Instance we will be deploying SpringBoot Application , for that we need to install Docker so that we can create an image from Dockerfile and Minikube and Kubectl to deploy SpringBoot Application and SonarQube to do code Quality checks and Trivy to do scanning of Docker Images and Terrascan to scan K8s yaml files.
This is the script for Installing Docker in EC2 Instance :
This script is checking if Docker is already installed on the system by running the command systemctl status docker.service and checking the output for the string “active (running)”. If Docker is already installed and running, the script will print a message “Docker is installed successfully” and will display the version of Docker using the command docker –version.
If Docker is not already installed, the script will run a series of commands to install it on the system. First, it updates the package list and installs the necessary dependencies using the sudo apt update and sudo apt install commands.
Then, it adds the Docker repository to the system using the commands curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg and echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null.
After that, it updates the package list again and installs Docker using the commands sudo apt update and sudo apt install -y docker-ce. It then checks the status of the Docker service using sudo systemctl status docker and adds the current user to the Docker group using sudo usermod -aG docker $USER. This allows the user to run Docker commands without the need for sudo.
See, Docker is installed in EC2 Instance.
This is the script to run SonarQube Image in EC2 Instance :
Login into SonarQube : http://<PublicIP>:9000 . Use password and username as “admin” and change the password.
To create a project Click Project and click Manually and add Project Key and name and create the token
This is the script for Installing Kubectl in EC2 Instance :
This script is used to check if the Kubernetes command line tool, kubectl, is installed and at the correct version on the system.
The script starts by running the command “kubectl version –client” and redirecting the output to /dev/null. The exit code of this command is stored in the variable $?. If the command returns an exit code of 0, it means that kubectl is installed and the script will print “kubectl is installed” followed by the version of kubectl.
If kubectl is not installed, the script proceeds to download the latest stable version of kubectl for Linux and the sha256 checksum for that version of kubectl. The script then uses the command “sha256sum –check” to verify that the downloaded kubectl binary matches the sha256 checksum. If the checksum is valid, the script uses the “install” command to install kubectl in the /usr/local/bin directory with the appropriate permissions. Finally, the script prints the version of kubectl after installation.
See, Kubectl is installed in EC2 Instance.
This is the script for Installing Minikube in EC2 Instance :
See, Minikube is running on EC2 Instance
This is the script for Installing Trivy in EC2 Instance :
The script checks if the Trivy vulnerability scanner is installed on the system and, if not, it will download the Trivy package and install it using the dpkg command.
The script uses the command command -v to check if the Trivy executable is in the system’s PATH. If the command returns a non-zero exit status, it means that Trivy is not installed. The script then proceeds to download the package by using wget and installs it using dpkg.
See, Trivy is running on EC2 Instance
This is the script for Installing Terrascan in EC2 Instance :
The script checks if the Terrascan security scanner is installed on the system and, if not, it will download the Terrascan package and install it by extracting it and moving the binary to a directory in the system’s PATH and make it executable.
The script uses the command command -v to check if the Terrascan executable is in the system’s PATH. If the command returns a non-zero exit status, it means that Terrascan is not installed. The script then proceeds to download the package by using curl, extract the binary file and move it to a directory in the PATH and make it executable, then runs Terrascan.
See, Terrascan is running on EC2 Instance