diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b20529d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "FSharp.suggestGitignore": false, + "java.configuration.updateBuildConfiguration": "interactive", + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/DEVOPS-main/DOCKER/Mini_Project/Docker_commands b/DEVOPS-main/DOCKER/Mini_Project/Docker_commands new file mode 100644 index 0000000..d405f45 --- /dev/null +++ b/DEVOPS-main/DOCKER/Mini_Project/Docker_commands @@ -0,0 +1,50 @@ +===================== +# Build image (from Dockerfile) +===================== +docker build -t project/myapp:v1 . +# 'project/myapp' is user-defined name + +===================== +# Create container (from Image) +===================== +docker run -dt --name container1 -p 80:80 project/myapp +# here 80:80 means : +# 'container1' is user-defined name + +===================== +# Access the content +===================== +# Open browser & use to access the content + +------------------------------------------------------------ +--- END --- +------------------------------------------------------------ +===================== +# OTHER COMMANDS +===================== + +===================== +# Go inside container +===================== +docker exec -it /bin/bash + +===================== +# Stop & remove all containers +===================== +docker stop $(docker ps -aq) +docker rm $(docker ps -aq) + +===================== +# Delete all docker images +===================== +docker image prune -af + +===================== +# To delete all content from text file using 'vi' +# use 'Esc:%d' +===================== + +===================== +# To check which directories are consuming space in Linux +===================== +du -h /usr | sort -rh | head -n 10 diff --git a/DEVOPS-main/DOCKER/Mini_Project/Dockerfile b/DEVOPS-main/DOCKER/Mini_Project/Dockerfile new file mode 100644 index 0000000..7f5c5ab --- /dev/null +++ b/DEVOPS-main/DOCKER/Mini_Project/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu + +# Install Apache & Git +RUN apt-get update && \ + apt-get install -y apache2 git + +# Pull content from Github +RUN git clone https://github.com/iotbands1train/DevopsProject1.git +# Add content inside html directory +RUN cd DevopsProject/ && \ + cp -R * /var/www/html/ + +# Delete the Project directory after copying the files +RUN rm -rf DevopsProject + +# Start Apache +CMD ["apache2ctl", "-D", "FOREGROUND"] + +# Expose port 80 of container +EXPOSE 80 diff --git a/DEVOPS-main/DOCKER/Mini_Project/README.md b/DEVOPS-main/DOCKER/Mini_Project/README.md new file mode 100644 index 0000000..f8516e3 --- /dev/null +++ b/DEVOPS-main/DOCKER/Mini_Project/README.md @@ -0,0 +1,25 @@ +--- +# **DOCKER MINI PROJECT** +--- + +![image](https://github.com/pandacloud1/DEVOPS/assets/134182273/e7a14622-fc73-4036-b64c-e41f0f175b07) + +## Objective: +Pulling content from Github & exposing through container + +## Instructions: +1. Create EC2 instance & enable required ports (eg. 22, 80, 8080) in the security group +2. Install Docker + * *(https://github.com/pandacloud1/DEVOPS/tree/main/Installation_Scripts/Docker)* +3. Create Dockerfile as below: + * Install Git, Apache + * Pull content from Github + * Copy the content to /var/www/html/ location + * Start Apache service +4. Create Docker image from 'Dockerfile' +5. Create Container from Docker image exposing required port of the container with the local machine +6. Access the content from the browser using + +- *Dockerfile:* *(https://github.com/pandacloud1/DEVOPS/blob/main/DOCKER/Mini_Project/Dockerfile)* +- *Docker_Commands:* *(https://github.com/pandacloud1/DEVOPS/blob/main/DOCKER/Mini_Project/Docker_commands)* + diff --git a/DEVOPS-main/Installation_Scripts/Ansible/Amazon_Linux2/ansible.bash b/DEVOPS-main/Installation_Scripts/Ansible/Amazon_Linux2/ansible.bash new file mode 100644 index 0000000..0d655e1 --- /dev/null +++ b/DEVOPS-main/Installation_Scripts/Ansible/Amazon_Linux2/ansible.bash @@ -0,0 +1,14 @@ + +vi ansible.sh + +#!/bin/bash +sudo yum update -y +sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y +sudo yum install git python python-devel python-pip openssl ansible -y + + + +chmod a+x ansible.sh +./ansible.sh + + diff --git a/DEVOPS-main/Installation_Scripts/Docker/Amazon_Linux2/docker.bash b/DEVOPS-main/Installation_Scripts/Docker/Amazon_Linux2/docker.bash new file mode 100644 index 0000000..cd8a838 --- /dev/null +++ b/DEVOPS-main/Installation_Scripts/Docker/Amazon_Linux2/docker.bash @@ -0,0 +1,19 @@ +# REF: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-docker.html +#!/bin/bash +sudo yum update -y +sudo yum install docker -y +sudo systemctl start docker +sudo systemctl enable docker +# Add ec2-user to the docker group so that Docker commands can be run w/o using sudo. +sudo usermod -aG docker $USER && newgrp docker #(add normal user 'docker') +# sudo usermod -aG docker ec2-user +# To avoid below permission error +# Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock +sudo chmod 777 /var/run/docker.sock + + +# chmod a+x docker.bash +# ./docker.bash + +chmod a+x docker.bash +./docker.bash \ No newline at end of file diff --git a/DEVOPS-main/Installation_Scripts/Git/Amazon_Linux2/git.bash b/DEVOPS-main/Installation_Scripts/Git/Amazon_Linux2/git.bash new file mode 100644 index 0000000..27b4f06 --- /dev/null +++ b/DEVOPS-main/Installation_Scripts/Git/Amazon_Linux2/git.bash @@ -0,0 +1,3 @@ +#!/bin/bash +sudo yum update -y +sudo yum install git -y diff --git a/DEVOPS-main/Installation_Scripts/Jenkins/Amazon_Linux/jenkins.bash b/DEVOPS-main/Installation_Scripts/Jenkins/Amazon_Linux/jenkins.bash new file mode 100644 index 0000000..be25644 --- /dev/null +++ b/DEVOPS-main/Installation_Scripts/Jenkins/Amazon_Linux/jenkins.bash @@ -0,0 +1,35 @@ + +# jenkins.sh +vi jenkins.sh + +#!/bin/bash +# REF: (https://www.jenkins.io/doc/tutorials/tutorial-for-installing-jenkins-on-AWS/) +# NOTE: +# 1. Jenkins works on port 8080, so keep the port open while creating EC2 instance +# 2. Jenkins also requires Java & supports versions 11,17 & 21 + +sudo yum update -y +sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo +sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key +sudo yum install java-17-amazon-corretto -y +sudo yum install jenkins -y +sudo /usr/sbin/alternatives --config java +sudo /usr/sbin/alternatives --config javac +sudo systemctl enable jenkins +sudo systemctl start jenkins + +# Get Jenkins_Public_IP +ip=$(curl ifconfig.me) +port=8080 +echo "Access your Jenkins here --> http://$ip:$port" + +# Generate Jenkins initial login password +pass=$(sudo cat /var/lib/jenkins/secrets/initialAdminPassword) +echo "Your Jenkins Initial Password: $pass" + +# In case if Jenkins fails to starts, try to set Java version to 11,17,21 using below command +# sudo /usr/sbin/alternatives --config java +# (Select the relevant Java version: 11,17 or 21) + +chmod a+x jenkins.sh +./jenkins.sh \ No newline at end of file diff --git a/DEVOPS-main/Installation_Scripts/Kubernetes/03-k8s.sh b/DEVOPS-main/Installation_Scripts/Kubernetes/03-k8s.sh new file mode 100644 index 0000000..452a45b --- /dev/null +++ b/DEVOPS-main/Installation_Scripts/Kubernetes/03-k8s.sh @@ -0,0 +1,23 @@ + +vi k8s.bash + + +# install kubectl + +# k8s.bash + +#!/bin/bash +curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" +curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl +curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256" +echo "$(cat kubectl.sha256) kubectl" | sha256sum --check +sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl +sudo chmod +x kubectl +sudo mkdir -p ~/.local/bin +sudo mv ./kubectl ~/.local/bin/kubectl +kubectl version + +# execute bash +chmod a+x k8s.bash +./k8s.bash + diff --git a/DEVOPS-main/Installation_Scripts/Kubernetes/Amazon_Linux2/k8s_kubeadm b/DEVOPS-main/Installation_Scripts/Kubernetes/Amazon_Linux2/k8s_kubeadm new file mode 100644 index 0000000..b8ce4ef --- /dev/null +++ b/DEVOPS-main/Installation_Scripts/Kubernetes/Amazon_Linux2/k8s_kubeadm @@ -0,0 +1,43 @@ +# ------------------- +# Install Docker +# ------------------- +# REF: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-docker.html +#!/bin/bash +sudo yum update -y +sudo yum install docker -y +sudo systemctl start docker +sudo systemctl enable docker +sudo usermod -aG docker $USER && newgrp docker + +# ------------------- +# Install K8S (Kubeadm) +# ------------------- +# REF: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/ +sudo setenforce 0 +sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config + +cat < -n jenkins -- /bin/bash + +# To get Jenkins password after helm setup +kubectl exec --namespace jenkins -it svc/my-jenkins-app -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password && echo \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/Helm_&_HelmCharts/Jenkins_using_Helm.txt b/DEVOPS-main/KUBERNETES/Helm_&_HelmCharts/Jenkins_using_Helm.txt new file mode 100644 index 0000000..a3e72a0 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Helm_&_HelmCharts/Jenkins_using_Helm.txt @@ -0,0 +1,15 @@ + +# Installing Jenkins application using Helm +# Reference: https://github.com/jenkinsci/helm-charts + +kubectl create namespace jenkins +helm repo add jenkins https://charts.jenkins.io #(to add charts related to jenkins application) +helm repo update #(to update the repository) +helm search repo jenkins #(to search 'jenkins' in helm repository) +helm install jenkins jenkins/jenkins -n jenkins +kubectl get pods -n jenkins + +kubectl exec -it -n jenkins -- /bin/bash + +# To get Jenkins password after helm setup +kubectl exec --namespace jenkins -it svc/my-jenkins-app -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password && echo \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm In Node.sh b/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm In Node.sh new file mode 100644 index 0000000..68e5ea8 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm In Node.sh @@ -0,0 +1,54 @@ +# ------------------------ +# ------------------------ +# INSTALLING KUBEADM IN NODE [UBUNTU 20.04] +# ------------------------ +# ------------------------ +# Reference: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#k8s-install-0 + +# Updating the OS +sudo apt-get update -y +# apt-transport-https may be a dummy package; if so, you can skip that package + +# ------------------------ +# INSTALL DOCKER +# ------------------------ +sudo apt update -y #(update the OS) +sudo apt install docker.io -y #(install docker) +sudo service docker start #(start docker service) + +# ------------------------ +# INSTALL KUBECTL +# ------------------------ + +# Install package for Kubernetes apt repository +sudo apt-get install -y apt-transport-https ca-certificates curl gpg + +# In older release less than Ubuntu 22.04 below directory must be created +sudo mkdir -m 755 /etc/apt/keyrings + +# Download the public signing key for the Kubernetes package repositories +curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + +# Add the appropriate Kubernetes apt repository +# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list +echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list + +# Update the apt package index, install kubelet, kubeadm and kubectl +sudo apt-get update -y +sudo apt-get install -y kubelet kubeadm kubectl + +sudo apt-mark hold kubelet kubeadm kubectl + +# ------------------------ +# Check Kubernetes version +# ------------------------ +kubectl version + + +# ============================= + +# Run these commands separately +sudo su - +# + +systemctl restart kubelet diff --git a/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm In Node.txt b/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm In Node.txt new file mode 100644 index 0000000..68e5ea8 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm In Node.txt @@ -0,0 +1,54 @@ +# ------------------------ +# ------------------------ +# INSTALLING KUBEADM IN NODE [UBUNTU 20.04] +# ------------------------ +# ------------------------ +# Reference: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#k8s-install-0 + +# Updating the OS +sudo apt-get update -y +# apt-transport-https may be a dummy package; if so, you can skip that package + +# ------------------------ +# INSTALL DOCKER +# ------------------------ +sudo apt update -y #(update the OS) +sudo apt install docker.io -y #(install docker) +sudo service docker start #(start docker service) + +# ------------------------ +# INSTALL KUBECTL +# ------------------------ + +# Install package for Kubernetes apt repository +sudo apt-get install -y apt-transport-https ca-certificates curl gpg + +# In older release less than Ubuntu 22.04 below directory must be created +sudo mkdir -m 755 /etc/apt/keyrings + +# Download the public signing key for the Kubernetes package repositories +curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + +# Add the appropriate Kubernetes apt repository +# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list +echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list + +# Update the apt package index, install kubelet, kubeadm and kubectl +sudo apt-get update -y +sudo apt-get install -y kubelet kubeadm kubectl + +sudo apt-mark hold kubelet kubeadm kubectl + +# ------------------------ +# Check Kubernetes version +# ------------------------ +kubectl version + + +# ============================= + +# Run these commands separately +sudo su - +# + +systemctl restart kubelet diff --git a/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm in Master.sh b/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm in Master.sh new file mode 100644 index 0000000..201dc1e --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm in Master.sh @@ -0,0 +1,64 @@ +# INSTALLING KUBEADM IN UBUNTU 20.04 +# Reference: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#k8s-install-0 + +# Updating the OS +sudo apt-get update -y +# apt-transport-https may be a dummy package; if so, you can skip that package + +# Installing Docker +sudo apt update -y #(update the OS) +sudo apt install docker.io -y #(install docker) +sudo service docker start #(start docker service) +# Add ec2-user to the docker group so that Docker commands can be run w/o using sudo. +sudo usermod -aG docker $USER && newgrp docker #(add normal user 'docker') +sudo chmod 777 /var/run/docker.sock + +# Install package for Kubernetes apt repository +sudo apt-get install -y apt-transport-https ca-certificates curl gpg + +# In older release less than Ubuntu 22.04 below directory must be created +sudo mkdir -m 755 /etc/apt/keyrings + +# Download the public signing key for the Kubernetes package repositories +curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + +# Add the appropriate Kubernetes apt repository +# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list +echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list + +# Update the apt package index, install kubelet, kubeadm and kubectl +sudo apt-get update -y +sudo apt-get install -y kubelet kubeadm kubectl + +#Check Kubernetes version +kubectl version + +sudo apt-mark hold kubelet kubeadm kubectl + + +# -------- + +# Initialize Master or Control Plane +# Reference link: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#considerations-about-apiserver-advertise-address-and-controlplaneendpoint + +sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=NumCPU --ignore-preflight-errors=Mem +# (Token will be generated for use in Node) + +mkdir -p $HOME/.kube +sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config +sudo chown $(id -u):$(id -g) $HOME/.kube/config + +kubectl apply -f https://docs.projectcalico.org/v3.18/manifests/calico.yaml +kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml +kubectl taint nodes --all node-role.kubernetes.io/control-plane- + +kubectl get pods -A +kubectl get nodes -o wide + + +# Note: +# 1. CG group driver setup can be skipped for Docker +# 2. Install only the above commands in Node & then paste the token in the node by becoming root user +# 3. Now check the nodes in master, if the node is still showing 'NotReady' then run systemctl restart kubelet + + diff --git a/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm in Master.txt b/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm in Master.txt new file mode 100644 index 0000000..201dc1e --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Installing K8s using Kubeadm/Installing Kubeadm in Master.txt @@ -0,0 +1,64 @@ +# INSTALLING KUBEADM IN UBUNTU 20.04 +# Reference: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#k8s-install-0 + +# Updating the OS +sudo apt-get update -y +# apt-transport-https may be a dummy package; if so, you can skip that package + +# Installing Docker +sudo apt update -y #(update the OS) +sudo apt install docker.io -y #(install docker) +sudo service docker start #(start docker service) +# Add ec2-user to the docker group so that Docker commands can be run w/o using sudo. +sudo usermod -aG docker $USER && newgrp docker #(add normal user 'docker') +sudo chmod 777 /var/run/docker.sock + +# Install package for Kubernetes apt repository +sudo apt-get install -y apt-transport-https ca-certificates curl gpg + +# In older release less than Ubuntu 22.04 below directory must be created +sudo mkdir -m 755 /etc/apt/keyrings + +# Download the public signing key for the Kubernetes package repositories +curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + +# Add the appropriate Kubernetes apt repository +# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list +echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list + +# Update the apt package index, install kubelet, kubeadm and kubectl +sudo apt-get update -y +sudo apt-get install -y kubelet kubeadm kubectl + +#Check Kubernetes version +kubectl version + +sudo apt-mark hold kubelet kubeadm kubectl + + +# -------- + +# Initialize Master or Control Plane +# Reference link: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#considerations-about-apiserver-advertise-address-and-controlplaneendpoint + +sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=NumCPU --ignore-preflight-errors=Mem +# (Token will be generated for use in Node) + +mkdir -p $HOME/.kube +sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config +sudo chown $(id -u):$(id -g) $HOME/.kube/config + +kubectl apply -f https://docs.projectcalico.org/v3.18/manifests/calico.yaml +kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml +kubectl taint nodes --all node-role.kubernetes.io/control-plane- + +kubectl get pods -A +kubectl get nodes -o wide + + +# Note: +# 1. CG group driver setup can be skipped for Docker +# 2. Install only the above commands in Node & then paste the token in the node by becoming root user +# 3. Now check the nodes in master, if the node is still showing 'NotReady' then run systemctl restart kubelet + + diff --git a/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Installing Minikube in EC2.sh b/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Installing Minikube in EC2.sh new file mode 100644 index 0000000..e0ecc4a --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Installing Minikube in EC2.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# ==================================== +# INSTALLING MINIKUBE IN UBUNTU 20.04 +# ==================================== +# Reference: https://minikube.sigs.k8s.io/docs/start/ + +# ------------------------ +# PRE-REQUISITE +# ------------------------ +# Min 2GB Memory, Min 2CPU's, Min 20GB Storage space (Use Instance_type: t2.medium) +# Ports: 22, 80, 443, 6443, 10250, 30000-32767 (Keep all ports open for practise) +# Docker + +# ------------------------ +# INSTALL DOCKER +# ------------------------ +sudo apt update -y #(update the OS) +sudo apt install docker.io -y #(install docker) +sudo service docker start #(start docker service) +# Add ec2-user to the docker group so that Docker commands can be run w/o using sudo. +sudo usermod -aG docker $USER && newgrp docker #(add normal user 'docker') +sudo usermod -aG docker ec2-user +sudo chmod 777 /var/run/docker.sock + +# ------------------------ +# INSTALL MINKUBE +# ------------------------ +curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb +sudo dpkg -i minikube_latest_amd64.deb +minikube start + +# ------------------------ +# INSTALL KUBECTL +# ------------------------ + +# Install package for Kubernetes apt repository +sudo apt-get install -y apt-transport-https ca-certificates curl gpg + +# In older release less than Ubuntu 22.04 below directory must be created +sudo mkdir -m 755 /etc/apt/keyrings + +# Download the public signing key for the Kubernetes package repositories +curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + +# Add the appropriate Kubernetes apt repository +# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list +echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list + +# Update the apt package index, install kubectl +sudo apt-get update -y +sudo apt-get install -y kubectl + + + diff --git a/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Installing Minikube in EC2.txt b/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Installing Minikube in EC2.txt new file mode 100644 index 0000000..e0ecc4a --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Installing Minikube in EC2.txt @@ -0,0 +1,54 @@ +#!/bin/bash +# ==================================== +# INSTALLING MINIKUBE IN UBUNTU 20.04 +# ==================================== +# Reference: https://minikube.sigs.k8s.io/docs/start/ + +# ------------------------ +# PRE-REQUISITE +# ------------------------ +# Min 2GB Memory, Min 2CPU's, Min 20GB Storage space (Use Instance_type: t2.medium) +# Ports: 22, 80, 443, 6443, 10250, 30000-32767 (Keep all ports open for practise) +# Docker + +# ------------------------ +# INSTALL DOCKER +# ------------------------ +sudo apt update -y #(update the OS) +sudo apt install docker.io -y #(install docker) +sudo service docker start #(start docker service) +# Add ec2-user to the docker group so that Docker commands can be run w/o using sudo. +sudo usermod -aG docker $USER && newgrp docker #(add normal user 'docker') +sudo usermod -aG docker ec2-user +sudo chmod 777 /var/run/docker.sock + +# ------------------------ +# INSTALL MINKUBE +# ------------------------ +curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb +sudo dpkg -i minikube_latest_amd64.deb +minikube start + +# ------------------------ +# INSTALL KUBECTL +# ------------------------ + +# Install package for Kubernetes apt repository +sudo apt-get install -y apt-transport-https ca-certificates curl gpg + +# In older release less than Ubuntu 22.04 below directory must be created +sudo mkdir -m 755 /etc/apt/keyrings + +# Download the public signing key for the Kubernetes package repositories +curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + +# Add the appropriate Kubernetes apt repository +# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list +echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list + +# Update the apt package index, install kubectl +sudo apt-get update -y +sudo apt-get install -y kubectl + + + diff --git a/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Opening Minikube tunnel.sh b/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Opening Minikube tunnel.sh new file mode 100644 index 0000000..bd2fd90 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Opening Minikube tunnel.sh @@ -0,0 +1,2 @@ +# Open the below command in new tab when exposing ports +minikube tunnel \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Opening Minikube tunnel.txt b/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Opening Minikube tunnel.txt new file mode 100644 index 0000000..bd2fd90 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/Installing K8s using Minikube/Opening Minikube tunnel.txt @@ -0,0 +1,2 @@ +# Open the below command in new tab when exposing ports +minikube tunnel \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/1 b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/1 new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/1 @@ -0,0 +1 @@ +1 diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/1. Pod.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/1. Pod.txt new file mode 100644 index 0000000..cc70538 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/1. Pod.txt @@ -0,0 +1,23 @@ +--- +apiVersion: v1 +kind: Pod +metadata: + name: my-pod1 +spec: + containers: + - name: container1 + image: httpd:latest +... + +# COMMANDS: +# kubectl apply -f pod.yaml +# kubectl get pods #(to see list of pods) +# kubectl exec -- /bin/bash #(to go inside the pod/container) +# httpd -version #(to see the apache version) +# exit #(to exit from the pod) + +# NOTE: +# Pod can be easily deleted by running below +# kubectl delete pod +# To avoid losing pod, use 'ReplicationController' or 'ReplicaSet' or 'Deployment') +# 'ReplicationController' is old form of K8s & not used anymore \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/2. ReplicaSet.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/2. ReplicaSet.txt new file mode 100644 index 0000000..37f050d --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/2. ReplicaSet.txt @@ -0,0 +1,46 @@ +# TIP: +# 1. To use 'ReplicaSet' instead of 'Pod' we need to add 'replicas', 'selectors' & 'template' under spec (RST) +# 2. The entire metadata of pod will go under 'template' (w/ labels added) +# 3. The 'apiVersion' of 'ReplicaSet' is 'apps/v1' + +--- +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: my-replicaset +spec: + replicas: 1 + selector: + matchLabels: + name: my-pod1 + template: + metadata: + labels: + name: my-pod1 + spec: + containers: + - name: container1 + image: httpd:latest +... + +# COMMANDS: +# kubectl apply -f .yaml +# kubectl get replicaset #(to check if replicaset is created) +# kubectl get pods #(to see if the pods are in running state) +# kubectl delete pods #(try deleting the pod, it will get deleted & new pod will get created) +# modify the code with more replicas #(you can create more replicas, if required) +# exit #(to exit from the pod) + +# To modify the code, first delete the replicaset +# kubectl delete replicaset +# Then edit the yaml file with desired replicas +# Then apply the yaml file +# kubectl apply -f .yaml + +# NOTE: +# ReplicationController is an old form of K8s, hence we are not learning it practically +# Since 'ReplicaSet' cannot Rollback/ Update, hence we can use 'Deployment' object. +# In real-time, we use 'Deployment' only & not 'ReplicaSet' + + + diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/3. Deployment.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/3. Deployment.txt new file mode 100644 index 0000000..be6cb23 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/3. Deployment.txt @@ -0,0 +1,28 @@ +# TIP: +# 1. Replace 'kind: ReplicaSet' --> 'kind: Deployment' +# 2. Change the name under 'metadata' & create replicas as required + + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment +spec: + replicas: 3 + selector: + matchLabels: + name: my-pod1 + template: + metadata: + labels: + name: my-pod1 + spec: + containers: + - name: container1 + image: httpd:latest +... + + +# NOTE: +# Deployment itself cannot expose pods to outside world, we need to combine it with 'Service' \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/4.1 Service - NodePort.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/4.1 Service - NodePort.txt new file mode 100644 index 0000000..dd598e2 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/4.1 Service - NodePort.txt @@ -0,0 +1,25 @@ +# TIP: +# 1. To create 'Service' manifest, remember phrase 'The Service Provider' (T,S,P) +# 2. Add 'type', 'selector' & 'ports' (The Service Provider) +# 3. Here 'port= service-port-no' & 'targetPort= pod-port-no' +# 4. Don't forget to add the 'selector' to select the relevant labelled 'Deployment' + +--- +apiVersion: v1 +kind: Service +metadata: + name: my-service +spec: + type: NodePort + selector: + name: my-pod1 + ports: + - protocol: TCP + port: 80 #(service-port) + targetPort: 80 #(pod-port) +... + +# NOTE: +# ClusterIP gets automatically created along with 'NodePort', which is default behaviour & meant is for cluster internal communication +# To allow networking, open SSH terminal in separate tab & run 'minikube tunnel' +# Then check curl must work in SSH terminal \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/4.2 Service - LoadBalancer.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/4.2 Service - LoadBalancer.txt new file mode 100644 index 0000000..2f18400 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/4.2 Service - LoadBalancer.txt @@ -0,0 +1,25 @@ +# TIP: +# 1. To create 'Service' manifest, remember phrase 'The Service Provider' +# 2. Add 'type', 'selector' & 'ports' (The Service Provider) +# 3. Here 'port= service-port-no' & 'targetPort= pod-port-no' +# 4. Don't forget to add the 'selector' to select the relevant labelled 'Deployment' + +--- +apiVersion: v1 +kind: Service +metadata: + name: my-service +spec: + type: LoadBalancer + selector: + name: my-pod1 + ports: + - protocol: TCP + port: 80 #(service-port) + targetPort: 80 #(pod-port) +... + +# NOTE: +# ClusterIP gets automatically created along with 'NodePort', which is default behaviour & meant is for cluster internal communication +# To allow networking, open SSH terminal in separate tab & run 'minikube tunnel' +# Then check curl must work in SSH terminal \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/5.1 PV & PVC.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/5.1 PV & PVC.txt new file mode 100644 index 0000000..479833e --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/5.1 PV & PVC.txt @@ -0,0 +1,42 @@ +# NOTE: +# 1. We need to manually create an EBS from AWS & get the volumeID & enter in below manifest +# 2. EBS must be created in same region as EC2 +# 3. EBS is integrated with PV & Pod is integrated with PVC + +# PersistentVolume yaml file + +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: my-pv +spec: + capacity: + storage: 20Gi + volumeMode: Filesystem + accessModes: + - ReadWriteOnce + awsElasticBlockStore: + volumeID: vol-0e4686933f1c2c88e #(Replace with your EBS volume ID) + fsType: ext4 + persistentVolumeReclaimPolicy: Retain +... + +# PersistentVolumeClaim yaml file + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: my-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi + storageClassName: standard #(storage class is standard by default, same can be checked using kubectl get storageclass) + selector: + matchLabels: + name: my-pv +... \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/5.2 Pod with PV.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/5.2 Pod with PV.txt new file mode 100644 index 0000000..a64fb75 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/5.2 Pod with PV.txt @@ -0,0 +1,21 @@ +# NOTE: +1. Pod is integrated using PVC +2. EBS is integrated using PV + +--- +apiVersion: v1 +kind: Pod +metadata: + name: my-pod1 +spec: + containers: + - name: container1 + image: httpd:latest + volumeMounts: + - name: my-volume + mountPath: /data + volumes: + - name: my-volume + persistentVolumeClaim: + claimName: my-pvc #(paste your pvc name here) +... \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.1 ConfigMap.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.1 ConfigMap.txt new file mode 100644 index 0000000..1f4eb1f --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.1 ConfigMap.txt @@ -0,0 +1,17 @@ +# NOTE: +# 1. ConfigMap contains configuration data only +# 2. If you want to store any confidential data, then use 'Secrets' + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: my-configmap +data: + name: "my-app" + marketname: "blue-ocean" + marketID: "bo" + category: "non-prod" + env: "uat" + url: "my-blue-ocean.com" +... \ No newline at end of file diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.2 Pod with ConfigMap.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.2 Pod with ConfigMap.txt new file mode 100644 index 0000000..644d9c2 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.2 Pod with ConfigMap.txt @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: mypod2 +spec: + containers: + - name: mycontainer + image: myimage + volumeMounts: + - name: config-volume + mountPath: /etc/config + volumes: + - name: config-volume + configMap: + name: my-configmap #(must match the name of configMap) diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.3 Pod with ConfigMap.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.3 Pod with ConfigMap.txt new file mode 100644 index 0000000..f55bf01 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/6.3 Pod with ConfigMap.txt @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: mypod +spec: + containers: + - name: mycontainer + image: myimage + volumeMounts: + - name: config-volume + mountPath: /etc/config + volumes: + - name: config-volume + configMap: + name: my-configmap diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/7.1 Secret.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/7.1 Secret.txt new file mode 100644 index 0000000..35a3098 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/7.1 Secret.txt @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: my-database-secret +type: Opaque +data: + username: dXNlcm5hbWU= # base64-encoded username (e.g., "username") + password: cGFzc3dvcmQ= # base64-encoded password (e.g., "password") diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/7.2 Pod with Secret.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/7.2 Pod with Secret.txt new file mode 100644 index 0000000..a39d266 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/7.2 Pod with Secret.txt @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: mypod4 +spec: + containers: + - name: mycontainer + image: httpd:latest + volumeMounts: + - name: secret-volume + mountPath: /etc/secrets + volumes: + - name: secret-volume + secret: + secretName: my-database-secret #(mention your secret name) diff --git a/DEVOPS-main/KUBERNETES/K8S_OBJECTS/8. Namespace.txt b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/8. Namespace.txt new file mode 100644 index 0000000..3b11dd1 --- /dev/null +++ b/DEVOPS-main/KUBERNETES/K8S_OBJECTS/8. Namespace.txt @@ -0,0 +1,17 @@ +# Namespaces can be created by imperative command as below + +kubectl create namespace + +# eg: +kubectl create ns sit +kubectl create ns uat +kubectl create ns dev + +# Example to create pod in sit environment +kubectl apply -f pod.yaml -n sit +kubectl get pods -n sit +kubectl describe pods -n sit + +# NOTE: +# For Non-prod environments we have: DEV, SIT & UAT +# For Production environments we have: STAGING & PROD \ No newline at end of file diff --git a/Jenkinsfile-CD b/Jenkinsfile-CD index ac4dbbd..a3e0abb 100644 --- a/Jenkinsfile-CD +++ b/Jenkinsfile-CD @@ -6,9 +6,9 @@ pipeline { agent any // DECLARE THE VARIABLES HERE: environment { - NODE_IP = '' // paste your Node-Server private IP here + NODE_IP = '172.31.30.1' // paste your Node-Server private IP here EC2_NAME = "ec2-user" // enter your AWS EC2 username - PIPELINE_NAME = "CI-PIPELINE" // enter your pipeline name here + PIPELINE_NAME = "CI-PIPELINE-V2" // enter your pipeline name here PROJECT_NAME = "DevopsProject1" // enter your Devops project name here } @@ -16,7 +16,7 @@ pipeline { stage("1. Pull Files") { // Copy K8s manifest files from Master-Server workspace to Node-server steps { - sshagent(['my_ec2_creds']) { // install 'ssh agent' plugin & generate 'ssh-agent' pipeline syntax generator + sshagent(['my_key']) { // install 'ssh agent' plugin & generate 'ssh-agent' pipeline syntax generator sh "ssh -o StrictHostKeyChecking=no ${EC2_NAME}@${NODE_IP}" // enter your Node Server's private IP here sh "scp /var/lib/jenkins/workspace/${PIPELINE_NAME}/${PROJECT_NAME}/deployment.yaml ${EC2_NAME}@${NODE_IP}:/home/ec2-user/" sh "scp /var/lib/jenkins/workspace/${PIPELINE_NAME}/${PROJECT_NAME}/service.yaml ${EC2_NAME}@${NODE_IP}:/home/ec2-user/" @@ -37,7 +37,7 @@ pipeline { // i. Ensure to establish passwordless connection between Master & Node first // ii. Your deployment.yaml file must contain the Dockerhub image within the container block steps { - sshagent(['my_ec2_creds']) { // store EC2 username & pem-key in Jenkins credentials + sshagent(['my_key']) { // store EC2 username & pem-key in Jenkins credentials sh "ssh -o StrictHostKeyChecking=no ${EC2_NAME}@${NODE_IP}" // enter your Node-Server private IP here sh "ssh -o StrictHostKeyChecking=no ${EC2_NAME}@${NODE_IP} kubectl apply -f deployment.yaml" sh "ssh -o StrictHostKeyChecking=no ${EC2_NAME}@${NODE_IP} kubectl apply -f service.yaml" @@ -47,4 +47,4 @@ pipeline { } } } -} +} \ No newline at end of file diff --git a/Jenkinsfile-CI b/Jenkinsfile-CI index f480b2e..c56f6bb 100644 --- a/Jenkinsfile-CI +++ b/Jenkinsfile-CI @@ -8,7 +8,8 @@ pipeline { agent any // DECLARE THE VARIABLES HERE: environment { - DOCKER_USERNAME = "nasirpatel" // check the 'ID' in your Jenkins credentials + DOCKER_USERNAME = "iotbands1train" // check the 'ID' in your Jenkins credentials + PIPELINE_NAME = "CI-PIPELINE-V2" } stages { @@ -25,7 +26,7 @@ pipeline { steps { dir ("DevopsProject1"){ script { - git branch: 'main', url: 'https://github.com/pandacloud1/DevopsProject1.git' + git branch: 'main', url: "https://github.com/iotbands1train/DevopsProject1.git" } } } diff --git a/README.md b/README.md index 3a74cec..f2d6336 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Devops-Project. -![Tools](https://github.com/pandacloud1/DevopsProject1/assets/134182273/b553e105-136d-4ce4-93ec-540809cdc6ee) +![alt text](image.png) This repository contains the following components: diff --git a/deployment.yaml b/deployment.yaml index f2f582f..ef25f2a 100644 --- a/deployment.yaml +++ b/deployment.yaml @@ -15,6 +15,6 @@ spec: spec: containers: - name: mycontainer - image: nasirpatel/ci-pipeline:latest # replace with your Docker-image pushed on Dockerhub + image: iotbands1train/ci-pipeline-v2:latest # replace with your Docker-image pushed on Dockerhub ports: - containerPort: 8080 diff --git a/image.png b/image.png new file mode 100644 index 0000000..d4ab902 Binary files /dev/null and b/image.png differ diff --git a/pom.xml b/pom.xml index 3512c33..e5a3659 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,16 @@ org.springframework.boot spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + diff --git a/src/main/java/com/javatechie/DevopsIntegrationApplication.java b/src/main/java/com/javatechie/DevopsIntegrationApplication.java index 8084fe6..31e9d6b 100644 --- a/src/main/java/com/javatechie/DevopsIntegrationApplication.java +++ b/src/main/java/com/javatechie/DevopsIntegrationApplication.java @@ -14,6 +14,12 @@ public String message(){ return "Welcome to our DevOps Project !!"; } + @GetMapping("/welcome") + public String welcome(){ + int x=1; + return "Welcome to our DevOps Project !!"+x; + } + public static void main(String[] args) { SpringApplication.run(DevopsIntegrationApplication.class, args); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29..9e91d82 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1,3 @@ +server.port=8080 +# start dispatcherServlet path at /api +server.servlet.context-path=/api \ No newline at end of file diff --git a/target/classes/META-INF/build-info.properties b/target/classes/META-INF/build-info.properties new file mode 100644 index 0000000..e12f226 --- /dev/null +++ b/target/classes/META-INF/build-info.properties @@ -0,0 +1,5 @@ +build.artifact=devops-integration +build.group=com.javatechie +build.name=devops-integration +build.time=2024-04-24T11\:18\:07.818Z +build.version=0.0.1-SNAPSHOT diff --git a/target/classes/application.properties b/target/classes/application.properties new file mode 100644 index 0000000..9e91d82 --- /dev/null +++ b/target/classes/application.properties @@ -0,0 +1,3 @@ +server.port=8080 +# start dispatcherServlet path at /api +server.servlet.context-path=/api \ No newline at end of file diff --git a/target/classes/application.yml b/target/classes/application.yml new file mode 100644 index 0000000..c378083 --- /dev/null +++ b/target/classes/application.yml @@ -0,0 +1,8 @@ +management: + endpoints: + web: + exposure: + include: + - "*" + server: + port: 8081 \ No newline at end of file diff --git a/target/classes/com/javatechie/DevopsIntegrationApplication.class b/target/classes/com/javatechie/DevopsIntegrationApplication.class new file mode 100644 index 0000000..753dbca Binary files /dev/null and b/target/classes/com/javatechie/DevopsIntegrationApplication.class differ diff --git a/target/classes/git.properties b/target/classes/git.properties new file mode 100644 index 0000000..32c196f --- /dev/null +++ b/target/classes/git.properties @@ -0,0 +1,26 @@ +#Generated by Git-Commit-Id-Plugin +git.branch=main +git.build.host=iotbengals +git.build.time=2024-04-24T06\:18\:07-0500 +git.build.user.email=iot.jacoy@gmail.com +git.build.user.name=iotbands1train +git.build.version=0.0.1-SNAPSHOT +git.closest.tag.commit.count= +git.closest.tag.name= +git.commit.author.time=2024-04-24T01\:54\:31-0500 +git.commit.committer.time=2024-04-24T01\:54\:31-0500 +git.commit.id=f54c59032c61938d5725b9fa52adf5a4578d7fe1 +git.commit.id.abbrev=f54c590 +git.commit.id.describe=f54c590-dirty +git.commit.id.describe-short=f54c590-dirty +git.commit.message.full=u2 +git.commit.message.short=u2 +git.commit.time=2024-04-24T01\:54\:31-0500 +git.commit.user.email=iot.jacoy@gmail.com +git.commit.user.name=iotbands1train +git.dirty=true +git.local.branch.ahead=0 +git.local.branch.behind=0 +git.remote.origin.url=https\://github.com/iotbands1train/DevopsProject1.git +git.tags= +git.total.commit.count=96 diff --git a/target/test-classes/com/javatechie/DevopsIntegrationApplicationTests.class b/target/test-classes/com/javatechie/DevopsIntegrationApplicationTests.class new file mode 100644 index 0000000..f85b325 Binary files /dev/null and b/target/test-classes/com/javatechie/DevopsIntegrationApplicationTests.class differ diff --git a/terraform_files/README.md b/terraform_files/README.md index b768ab8..3250790 100644 --- a/terraform_files/README.md +++ b/terraform_files/README.md @@ -1,7 +1,7 @@ ### TERRAFORM FILES --- -![image](https://github.com/pandacloud1/DevopsProject1/assets/134182273/42370753-d725-4706-a0fa-39d5281e6546) +![alt text](image.png) #### The above Terraform files will create 'Jenkins' & 'K8s' servers #### Master-Server --> Git, Maven, Docker, Trivy, Ansible diff --git a/terraform_files/main.tf b/terraform_files/main.tf index 44092e0..65c7059 100644 --- a/terraform_files/main.tf +++ b/terraform_files/main.tf @@ -2,7 +2,7 @@ # STEP1: CREATING A SECURITY GROUP FOR JENKINS SERVER # Description: Allow SSH, HTTP, HTTPS, 8080, 8081 resource "aws_security_group" "my_security_group1" { - name = "my-security-group1" + name = "my-security-group1-${timestamp()}" description = "Allow SSH, HTTP, HTTPS, 8080 for Jenkins & Maven" # SSH Inbound Rules @@ -54,7 +54,7 @@ resource "aws_security_group" "my_security_group1" { # Note: i. First create a pem-key manually from the AWS console #      ii. Copy it in the same directory as your terraform code resource "aws_instance" "my_ec2_instance1" { - ami = "ami-0cf10cdf9fcd62d37" + ami = "ami-080e449218d4434fa" instance_type = "t2.medium" vpc_security_group_ids = [aws_security_group.my_security_group1.id] key_name = "My_Key" # paste your key-name here, do not use extension '.pem' @@ -66,7 +66,7 @@ resource "aws_instance" "my_ec2_instance1" { } tags = { - Name = "MASTER-SERVER" + Name = "JENKINS-MASTER SERVER" } user_data = <<-EOF @@ -89,12 +89,11 @@ resource "aws_instance" "my_ec2_instance1" { host = self.public_ip } - inline = [ + inline = [ # wait for 200sec before EC2 initialization "sleep 200", # Install Git "sudo yum install git -y", - # Install Jenkins # REF: https://www.jenkins.io/doc/tutorials/tutorial-for-installing-jenkins-on-AWS/ "sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo", @@ -103,7 +102,6 @@ resource "aws_instance" "my_ec2_instance1" { "sudo yum install jenkins -y", "sudo systemctl enable jenkins", "sudo systemctl start jenkins", - # Install Docker # REF: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-docker.html "sudo yum update -y", @@ -114,11 +112,9 @@ resource "aws_instance" "my_ec2_instance1" { # To avoid below permission error # Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock "sudo chmod 666 /var/run/docker.sock", - # Install Trivy # REF: https://aquasecurity.github.io/trivy/v0.18.3/installation/ "sudo rpm -ivh https://github.com/aquasecurity/trivy/releases/download/v0.18.3/trivy_0.18.3_Linux-64bit.rpm", - # Install Ansible "sudo yum update -y", "sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y", diff --git a/terraform_files/node.tf b/terraform_files/node.tf index 688691b..14acf01 100644 --- a/terraform_files/node.tf +++ b/terraform_files/node.tf @@ -2,7 +2,7 @@ # STEP1: CREATING A SECURITY GROUP FOR DOCKER-K8S # Description: K8s requires ports 22, 80, 443, 6443, 8001, 10250, 30000-32767 resource "aws_security_group" "my_security_group2" { - name = "my-security-group4" + name = "my-security-group4-${timestamp()}" description = "Allow K8s ports" # SSH Inbound Rules @@ -75,10 +75,10 @@ resource "aws_security_group" "my_security_group2" { # Note: i. First create a pem-key manually from the AWS console #      ii. Copy it in the same directory as your terraform code resource "aws_instance" "my_ec2_instance2" { - ami = "ami-0cf10cdf9fcd62d37" + ami = "ami-080e449218d4434fa" instance_type = "t2.medium" # K8s requires min 2CPU & 4G RAM vpc_security_group_ids = [aws_security_group.my_security_group2.id] - key_name = "My_Key" # paste your key-name here, do not use extension '.pem' + key_name = "My_Key_2" # paste your key-name here, do not use extension '.pem' # Consider EBS volume 30GB root_block_device { @@ -87,7 +87,7 @@ resource "aws_instance" "my_ec2_instance2" { } tags = { - Name = "NODE-SERVER" + Name = "K8s-NODE SERVER" } # STEP3: USING REMOTE-EXEC PROVISIONER TO INSTALL TOOLS @@ -95,12 +95,12 @@ resource "aws_instance" "my_ec2_instance2" { # ESTABLISHING SSH CONNECTION WITH EC2 connection { type = "ssh" - private_key = file("./My_Key.pem") # replace with your key-name + private_key = file("./My_Key_2.pem") # replace with your key-name user = "ec2-user" host = self.public_ip } - inline = [ + inline = [ "sleep 200", # Install Docker @@ -110,7 +110,7 @@ resource "aws_instance" "my_ec2_instance2" { "sudo systemctl start docker", "sudo systemctl enable docker", "sudo chmod 777 /var/run/docker.sock", - + # Install K8s # REF: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/ "sudo setenforce 0", @@ -133,9 +133,9 @@ resource "aws_instance" "my_ec2_instance2" { "kubectl apply -f https://docs.projectcalico.org/v3.18/manifests/calico.yaml", "kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml", "kubectl taint nodes --all node-role.kubernetes.io/control-plane-", - ] - } - + ] + } + } # STEP3: OUTPUT PUBLIC IP OF EC2 INSTANCE diff --git a/terraform_files/provider.tf b/terraform_files/provider.tf index 325f324..e00f738 100644 --- a/terraform_files/provider.tf +++ b/terraform_files/provider.tf @@ -9,5 +9,5 @@ terraform { } #STEP2: DEFINE THE REGION (N. Virginia) provider "aws" { - region = "us-east-1" + region = "us-east-2" } \ No newline at end of file