Ex 8
Ex 8
Description:
Kubernetes and Docker are both popular technologies for managing containers, but they are
used for different purposes. Kubernetes is an orchestration platform that provides a higher-
level abstraction for managing containers, while Docker is a containerization technology
that provides a lower-level runtime for containers.
To integrate Kubernetes and Docker, you need to use Docker to build and package your
application as a container image, and then use Kubernetes to manage and orchestrate the
containers.
Prerequisites
1. Windows OS
Ensure your system has Windows 10/11 with WSL2 (Windows Subsystem for Linux)
enabled.
2. Installed Tools:
- Docker Desktop for Windows
- Kubernetes (enabled within Docker Desktop)
- A text editor (e.g., Visual Studio Code, Notepad++)
- Command Prompt/PowerShell/WSL Terminal
3. Cloud Account (Optional):
Access to a container registry like Docker Hub or Google Container Registry.
Steps
dockerfile
# Use a base image
FROM python:3.9-slim
# Install dependencies
RUN pip install -r requirements.txt
apiVersion: apps/v1
kind: Deployment
metadata:
name: k8s-demo
spec:
replicas: 2
selector:
matchLabels:
app: k8s-demo
template:
metadata:
labels:
app: k8s-demo
spec:
containers:
- name: k8s-demo
image: myusername/k8s-demo:1.0
ports:
- containerPort: 5000
apiVersion: v1
kind: Service
metadata:
name: k8s-demo-service
spec:
selector:
app: k8s-demo
ports:
- protocol: TCP
port: 80
targetPort: 5000
type: LoadBalancer
Result
By following this manual, you successfully integrated Kubernetes and Docker, built a
container image, deployed it to Kubernetes, and managed it effectively.