Kuberneetes Deployment
Kuberneetes Deployment
Objective:
The goal of this task is to deploy a Python server application using Kubernetes on Docker Desktop.
You will containerize the Python application using Docker, create a Kubernetes Deployment, and
expose it via a NodePort service so that it is accessible from other machines in the network.
Requirements:
o kubectl cluster-info
o Retrieve the assigned NodePort and test access using curl or a web browser.
7. Cleanup (Optional)
Expected Deliverables:
1. Python server application (app.py)
Success Criteria:
The application should be accessible from a browser or via curl using <Docker-Desktop-
IP>:<NodePort>.
Additional Notes:
curl http://<Docker-Desktop-IP>:<NodePort>
Ensure that Docker Desktop and Kubernetes are properly set up.
kubectl version
docker --version
FROM python:3.9
WORKDIR /app
EXPOSE 80
docker images
http://localhost:5000
To load a Docker image from Docker Desktop to a Kubernetes cluster set up with kubeadm
If multiple nodes need the image, push it to a private registry instead of manually transferring:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
ports:
- containerPort: 80
5.2 service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
type: NodePort
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30000
Example output:
Go to:
http://192.168.1.100:30007
or use curl:
curl http://192.168.1.100:30007
Expected output: