Skip to content
Open

Snap #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Bind role-to-service
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion EKS_Terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "aws" {
region = "ap-south-1"
region = "us-east-1"
}

resource "aws_vpc" "devopsshack_vpc" {
Expand Down
2 changes: 1 addition & 1 deletion EKS_Terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
**Jenkins and EKS Deployment with Terraform and Docker Setup**
<img width="241" height="209" alt="image" src="https://github.com/user-attachments/assets/9b228bee-5684-4710-b473-f1288a4afd01" />
<img width="241" height="209" alt="image" src="https://github.com/user-attachments/assets/a263490a-dde5-4a85-92ba-88f4de6244ff" />
<img width="241" height="209" alt="image" src="https://github.com/user-attachments/assets/a801fbf7-66ed-453d-a6c2-3db01b21d7dc" />
<img width="241" height="209" alt="image" src="https://github.com/user-attachments/assets/a3ffeec0-02e1-4d1a-9671-1b8410f57cff" />
<img width="241" height="209" alt="image" src="https://github.com/user-attachments/assets/ace329ae-271b-4ea9-ab60-5576c4209056" />

**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 <container_id> /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.

<img width="1152" height="648" alt="image" src="https://github.com/user-attachments/assets/992a09f1-f13b-4f63-ad6e-9d7770fca537" />


**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 <cluster_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 <secret_name> -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

<img width="245" height="215" alt="image" src="https://github.com/user-attachments/assets/8154f86f-d6a3-4645-971f-5c911b03341f" />
5 changes: 5 additions & 0 deletions ServiceAccount.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins
namespace: webapps
18 changes: 9 additions & 9 deletions deployment-service.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
63 changes: 63 additions & 0 deletions manjujenkins
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
}
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@
<distributionManagement>
<repository>
<id>maven-releases</id>
<url>http://13.235.245.200:8081/repository/maven-releases/</url>
<url>http://34.224.23.97:8081/repository/maven-releases/</url>
</repository>

<snapshotRepository>
<id>maven-snapshots</id>
<url>http://13.235.245.200:8081/repository/maven-snapshots/</url>
<id>manju-snapshots</id>
<url>http://34.224.23.97:8081/repository/manju-snapshots/</url>
</snapshotRepository>
</distributionManagement>

Expand Down
38 changes: 38 additions & 0 deletions role.yml
Original file line number Diff line number Diff line change
@@ -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"]