PROJECT 1 — Nginx Web App Deployment + NodePort Service
This project teaches:
- Deployment
- ReplicaSets
- Pod scheduling
- NodePort service
- Access from browser
- Logs & cleanup
✅ Step 1 — Create Deployment YAML
Create: nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
Explanation
| Field | Meaning |
|---|---|
replicas: 3 | Runs 3 nginx pods |
selector.matchLabels | Deployment controls pods that match this label |
template.spec.containers | Defines the container in the pod |
containerPort: 80 | The port inside the container |
✅ Step 2 — Apply Deployment
kubectl apply -f nginx-deployment.yaml
kubectl get pods -o wide
You should see 3 running pods.
✅ Step 3 — Expose the Deployment (NodePort)
kubectl expose deployment nginx-deployment \
--type=NodePort --port=80
Check service:
kubectl get svc
✅ Step 4 — Access in Browser
Use Minikube to get the URL:
minikube service nginx-deployment --url
Open the URL → Nginx welcome page appears ✔
📌 Project 1 Monitoring + Logs + Cleanup
View logs:
kubectl logs -l app=nginx
Watch pod status:
kubectl get pods -w
Describe:
kubectl describe deployment nginx-deployment
Cleanup:
kubectl delete deployment nginx-deployment
kubectl delete svc nginx-deployment
PROJECT 2 -Apache Web Server + ConfigMap
1️⃣ Create ConfigMap
html-configmap.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
name: webpage-config
data:
index.html: |
<html>
<head><title>Kubernetes ConfigMap Demo</title></head>
<body>
<h1>Welcome to Kubernetes Project 2</h1>
<p>This page is served using Apache + ConfigMap!</p>
</body>
</html>
Apply:
kubectl apply -f html-configmap.yaml
2️⃣ Create Deployment
apache-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache-configmap-app
spec:
replicas: 2
selector:
matchLabels:
app: apache-config
template:
metadata:
labels:
app: apache-config
spec:
containers:
- name: apache-web
image: httpd:latest
ports:
- containerPort: 80
volumeMounts:
- name: html-volume
mountPath: /usr/local/apache2/htdocs/
volumes:
- name: html-volume
configMap:
name: webpage-config
Apply:
kubectl apply -f apache-deployment.yaml
Check pods:
kubectl get pods -o wide
You MUST see Running now.
3️⃣ Expose Service
kubectl expose deployment apache-configmap-app \
--type=NodePort \
--port=80
Check service:
kubectl get svc apache-configmap-app
4️⃣ Access in Browser
minikube service apache-configmap-app --url
Open the URL → You’ll see your HTML page.
🛠️ Stop, Logs, Monitoring
View logs:
kubectl logs -l app=apache-config
Describe pod:
kubectl describe pod -l app=apache-config
Scale down:
kubectl scale deployment apache-configmap-app --replicas=0
Delete all:
kubectl delete deployment apache-configmap-app
kubectl delete svc apache-configmap-app
kubectl delete configmap webpage-config
Project 2 teaches you how Kubernetes manages configuration separately from application code.
You deployed:
- An Apache web server (httpd container)
- A ConfigMap containing an HTML file
- A Deployment that mounts the ConfigMap as a volume
- A Service to expose the application
This project shows a fundamental Kubernetes concept:
Never bake configuration into Docker images → always inject it at runtime.
