https://github.com/tks-devops/k8s-deployment-project
k8s project using git github docker k8s yaml
https://github.com/tks-devops/k8s-deployment-project
aws-ec2 cicd docker-image dockerfile git github jenkins jenkinspipeline k8s kubectl kubernetes kubernetes-deployment linux minikube-commands minikube-docker-deployment minikube-setup shell-scripts yaml-configuration yaml-files
Last synced: 4 months ago
JSON representation
k8s project using git github docker k8s yaml
- Host: GitHub
- URL: https://github.com/tks-devops/k8s-deployment-project
- Owner: Tks-Devops
- Created: 2024-12-24T07:41:07.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-26T17:58:33.000Z (over 1 year ago)
- Last Synced: 2025-04-15T17:57:40.588Z (about 1 year ago)
- Topics: aws-ec2, cicd, docker-image, dockerfile, git, github, jenkins, jenkinspipeline, k8s, kubectl, kubernetes, kubernetes-deployment, linux, minikube-commands, minikube-docker-deployment, minikube-setup, shell-scripts, yaml-configuration, yaml-files
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Markdown
# Python App Deployment on Kubernetes
This project demonstrates how to deploy a Python application on a Kubernetes cluster using Docker, Kubernetes YAML files, and Jenkins for CI/CD automation.
## Project Overview
The project includes:
- A Python script (`app.py`).
- A Dockerfile to containerize the application.
- Kubernetes YAML files for deployment, service, and horizontal pod autoscaling.
- A Jenkins pipeline script for automating the build and deployment process.
## Prerequisites
- AWS Free Tier account with an EC2 instance.
- Minikube or any Kubernetes cluster.
- Docker installed on the system.
- Jenkins set up for CI/CD.
- Git installed on the system.
## Steps to Set Up the Project
### 1. Python Script
Save the following Python script as `app.py`:
```python
# app.py
print("Hello, Kubernetes!")
2. Dockerfile
Create a Dockerfile to containerize the Python application:
Dockerfile
FROM python:3.7-slim
WORKDIR /app
COPY app.py .
CMD ["python", "app.py"]
3. Kubernetes YAML Files
Deployment
YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: python-app
spec:
replicas: 2
selector:
matchLabels:
app: python-app
template:
metadata:
labels:
app: python-app
spec:
containers:
- name: python-app
image: :
ports:
- containerPort: 5000
Service
YAML
apiVersion: v1
kind: Service
metadata:
name: python-app-service
spec:
selector:
app: python-app
ports:
- protocol: TCP
port: 80
targetPort: 5000
type: LoadBalancer
Horizontal Pod Autoscaler
YAML
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: python-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: python-app
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
4. Jenkins Pipeline Script
Automate the build and deployment process with the following Jenkins pipeline script:
Groovy
pipeline {
agent any
environment {
DOCKER_IMAGE = "your-docker-image"
DOCKER_REGISTRY = "your-docker-registry"
BUILD_NUMBER = "${BUILD_NUMBER}"
}
stages {
stage('Clone Repository') {
steps {
git 'https://github.com/your-username/your-repository.git'
}
}
stage('Build Docker Image') {
steps {
script {
sh 'docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} .'
}
}
}
stage('Push Docker Image') {
steps {
script {
sh 'docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER}'
}
}
}
stage('Deploy to Kubernetes') {
steps {
script {
sh 'kubectl apply -f deployment.yaml'
sh 'kubectl apply -f service.yaml'
sh 'kubectl apply -f hpa.yaml'
}
}
}
}
}
1 vulnerability detected
Steps to Deploy
Clone this repository:
bash
git clone https://github.com/your-username/your-repository.git
cd your-repository
Build the Docker image:
docker build -t : .
Push the Docker image to a registry:
docker push :
Apply the Kubernetes YAML files:
bash
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f hpa.yaml
Verify the deployment:
bash
kubectl get pods
kubectl get svc
kubectl get hpa