diff --git a/Bind role-to-service b/Bind role-to-service new file mode 100644 index 00000000..ecb688f7 --- /dev/null +++ b/Bind role-to-service @@ -0,0 +1,13 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: app-rolebinding + namespace: webapps +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: app-role +subjects: +- namespace: webapps + kind: ServiceAccount + name: jenkins diff --git a/EKS_Terraform/main.tf b/EKS_Terraform/main.tf index cf18a035..593f96c4 100644 --- a/EKS_Terraform/main.tf +++ b/EKS_Terraform/main.tf @@ -1,5 +1,5 @@ provider "aws" { - region = "ap-south-1" + region = "us-east-1" } resource "aws_vpc" "devopsshack_vpc" { diff --git a/EKS_Terraform/variables.tf b/EKS_Terraform/variables.tf index dc712258..1fa3c8dd 100644 --- a/EKS_Terraform/variables.tf +++ b/EKS_Terraform/variables.tf @@ -1,5 +1,5 @@ variable "ssh_key_name" { description = "The name of the SSH key pair to use for instances" type = string - default = "DevOps" + default = "terraform" } diff --git a/README.md b/README.md new file mode 100644 index 00000000..550de444 --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +**Jenkins and EKS Deployment with Terraform and Docker Setup** +image +image +image +image +image + +**Overview** +This documentation outlines the steps to set up Jenkins and EKS clusters for deploying applications, using Docker, Terraform, and Kubernetes tools. The setup consists of launching Jenkins servers, configuring Docker and SonarQube, and deploying applications on an EKS cluster. + +****Step-by-Step Process** + +**1. Jenkins Server Setup**** +• Initially, launch 2 Jenkins servers (medium instances) for service queues. +• Additionally, launch one large Jenkins server instance. +• Install Java 17 JDK on Jenkins servers. +• Install Jenkins. +• Install Docker inside Jenkins servers. + +**2. Docker Socket Permissions** + +**Set permissions for Docker socket using:** +chmod 666 /var/run/docker.sock +**Install SonarQube on both Jenkins servers.** + +**Run SonarQube containers using Docker:** +docker run -d -p 9000:9000 sonarqube:lts-community +docker run -d -p 8081:8081 sonatype/nexus3 + +**To get the admin password for Nexus:** +docker exec -it /bin/bash +cat /nexus/admin.password + +**Jenkins Plugins Installation** +**• Install Tivm (presumably a plugin) in Jenkins servers.** + +**5. SonarQube Token Creation** +• Create tokens for SonarQube and Nexus artifact repositories. +• Configure Docker Hub credentials in Jenkins tools section and system configuration. + +**6. Plugins and Configurations** +• Update configuration files to allow plugin downloads and configurations. + +**7. EKS Cluster Deployment** +• Deploy applications using AWS EKS cluster. +• Setup EKS with Terraform scripts. + +image + + +**8. Secondary Server Setup** +Launch an additional server. +Install Terraform. +Launch EKS cluster. +Install kubectl. + +**Update Kubernetes config with:** +aws eks --region us-east-1 update-kubeconfig --name + +**Note:(It is used for authentication purpose)** + +**Verify nodes with:** +kubectl get nodes + +**Create Kubernetes resources:** +• Namespace +• ServiceAccount +• Role +• RoleBinding +• ⁠Create tokens for these resources. + +**Final steps** + +**Get secrets for namespace webapps:** + +**kubectl get secrets -n webapps** + +**kubectl describe secret -n webapps** + +**Use these secrets/tokens for authentication and deployment.** + +u will get the token copy the token and paste in jenkins credentials + +here is the deployment application for this pipeline + +image diff --git a/ServiceAccount.yml b/ServiceAccount.yml new file mode 100644 index 00000000..621b3dbc --- /dev/null +++ b/ServiceAccount.yml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins + namespace: webapps diff --git a/deployment-service.yml b/deployment-service.yml index 31aec78b..7b2b1cd2 100644 --- a/deployment-service.yml +++ b/deployment-service.yml @@ -1,33 +1,33 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: bloggingapp-deployment + name: productionno-1-deployment spec: selector: matchLabels: - app: bloggingapp + app: productionno-1 replicas: 2 template: metadata: labels: - app: bloggingapp + app: productionno-1 spec: containers: - - name: bloggingapp - image: adijaiswal/bloggingapp:latest # Updated image to private DockerHub image + - name: productionno-1 + image: manjugoud/productionno-1:latest # Updated image to private DockerHub image imagePullPolicy: Always ports: - containerPort: 8080 - imagePullSecrets: - - name: regcred # Reference to the Docker registry secret + # imagePullSecrets: + # - name: regcred # Reference to the Docker registry secret --- apiVersion: v1 kind: Service metadata: - name: bloggingapp-ssvc + name: productionno-1-ssvc spec: selector: - app: bloggingapp + app: productionno-1 ports: - protocol: "TCP" port: 80 diff --git a/manjujenkins b/manjujenkins new file mode 100644 index 00000000..0b67786b --- /dev/null +++ b/manjujenkins @@ -0,0 +1,63 @@ +pipeline { + agent any + + environment { + DEPLOY_REPO = "https://github.com/goudmanju/Hiring-app-argocd.git" + IMAGE_NAME = "manjugoud/productionno-1" + } + + parameters { + string(name: 'IMAGE_TAG', defaultValue: '', description: 'Docker image tag to deploy') + } + + stages { + stage('Validate Parameters') { + steps { + script { + if (!params.IMAGE_TAG?.trim()) { + error("IMAGE_TAG parameter is required! Please pass a valid Docker image tag.") + } + } + } + } + + stage('Checkout K8s Manifests') { + steps { + git branch: 'main', url: "${DEPLOY_REPO}" + } + } + + stage('Update Deployment YAML') { + steps { + script { + echo "Updating image tag in deployment.yaml to ${params.IMAGE_TAG}" + sh """ + sed -i 's|image: ${IMAGE_NAME}:.*|image: ${IMAGE_NAME}:${params.IMAGE_TAG}|g' dev/deployment.yaml + echo "----- Updated Deployment YAML -----" + cat dev/deployment.yaml + """ + } + } + } + + stage('Commit and Push Changes') { + steps { + withCredentials([usernamePassword(credentialsId: 'github', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { + sh """ + git config user.name "jenkins" + git config user.email "jenkins@ci.local" + git add . + git commit -m "Updated deployment.yaml with new image tag ${params.IMAGE_TAG}" + git push https://${GIT_USERNAME}:${GIT_PASSWORD}@git@github.com:goudmanju/Hiring-app-argocd.git main + """ + } + } + } + + stage('Trigger ArgoCD Sync (Optional)') { + steps { + echo "✅ ArgoCD will automatically detect the Git change and sync the deployment." + } + } + } +} diff --git a/pom.xml b/pom.xml index 3ed8ab2b..38617526 100644 --- a/pom.xml +++ b/pom.xml @@ -102,11 +102,12 @@ maven-releases - http://13.235.245.200:8081/repository/maven-releases/ + http://34.224.23.97:8081/repository/maven-releases/ + - maven-snapshots - http://13.235.245.200:8081/repository/maven-snapshots/ + manju-snapshots + http://34.224.23.97:8081/repository/manju-snapshots/ diff --git a/role.yml b/role.yml new file mode 100644 index 00000000..97d9f99e --- /dev/null +++ b/role.yml @@ -0,0 +1,38 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: app-role + namespace: webapps +rules: + - apiGroups: + - "" + - apps + - autoscaling + - batch + - extensions + - policy + - rbac.authorization.k8s.io + resources: + - pods + - secrets + - componentstatuses + - configmaps + - daemonsets + - deployments + - events + - endpoints + - horizontalpodautoscalers + - ingress + - jobs + - limitranges + - namespaces + - nodes + - pods + - persistentvolumes + - persistentvolumeclaims + - resourcequotas + - replicasets + - replicationcontrollers + - serviceaccounts + - services + verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]