This project demonstrates the deployment of applications on a Kubernetes cluster using Jenkins for Continuous Integration and Continuous Deployment (CI/CD).
The following diagram provides a high-level overview of the CI/CD pipeline:
Ensure you have the following installed and configured:
sample Jenkins pipeline script:
pipeline {
agent any
stages {
stage('Clone Repository') {
steps {
git 'https://github.com/your-repo.git'
}
}
stage('Build Docker Image') {
steps {
script {
docker.build("your-dockerhub-username/your-image-name:latest")
}
}
}
stage('Push to Docker Hub') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'dockerhub-credentials-id') {
docker.image("your-dockerhub-username/your-image-name:latest").push()
}
}
}
}
stage('Deploy to Kubernetes') {
steps {
kubernetesDeploy configs: 'k8s/deployment.yaml', kubeConfig: [path: 'path/to/kubeconfig']
}
}
}
}
Create a deployment.yaml
file for your Kubernetes deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: your-app
spec:
replicas: 3
selector:
matchLabels:
app: your-app
template:
metadata:
labels:
app: your-app
spec:
containers:
- name: your-app
image: your-dockerhub-username/your-image-name:latest
ports:
- containerPort: 80
By following the above steps, you can set up a Jenkins pipeline to automate the deployment of your applications on a Kubernetes cluster. This ensures a smooth CI/CD process, enabling rapid development and deployment.