containerization-and-devops

Class 13 - Apache Web App Deployment & Debugging

1. Objective

Deploy and manage an Apache web server and:


2. Step-by-Step Flow (IMPORTANT)

Step 1: Run a Pod (Basic)

kubectl run apache-pod --image=httpd
kubectl get pods

πŸ‘‰ Creates a single temporary pod

Step 2: Inspect Pod

kubectl describe pod apache-pod

Check for:

Step 3: Access App

kubectl port-forward pod/apache-pod 8081:80

Open: http://localhost:8081 πŸ‘‰ You will see: β€œIt works!”

Terminal Output

Run and Inspect Pod

Step 4: Delete Pod

kubectl delete pod apache-pod

Insight: Pod is deleted permanently. ❌ No recovery.


3. Why Pod is Not Enough

πŸ‘‰ Pod = Temporary πŸ‘‰ No self-healing


4. Convert to Deployment (IMPORTANT)

Step 5: Create Deployment

kubectl create deployment apache --image=httpd
kubectl get deployments
kubectl get pods

πŸ‘‰ Deployment manages pods.

Step 6: Expose Deployment

kubectl expose deployment apache --port=80 --type=NodePort

Access App:

kubectl port-forward service/apache 8082:80

Open: http://localhost:8082

Terminal Output

Deploy and Expose


5. Scaling (VERY IMPORTANT)

Step 7: Scale

kubectl scale deployment apache --replicas=2
kubectl get pods

πŸ‘‰ Now:

Observation: Refresh the browser. Requests are handled by different pods.

Terminal Output

Scaling


6. Debugging (MOST IMPORTANT SKILL)

Step 8: Break App

kubectl set image deployment/apache httpd=wrongimage

Step 9: Diagnose

kubectl get pods
kubectl describe pod <pod-name>

Error: ImagePullBackOff

Step 10: Fix

kubectl set image deployment/apache httpd=httpd

Terminal Output

Debugging


7. Work Inside Container

Step 11: Enter Pod

kubectl exec -it <pod-name> -- /bin/bash

Check Files:

ls /usr/local/apache2/htdocs

πŸ‘‰ This is where website files are stored.

Exit:

exit

8. Modify App (COOL PART)

kubectl exec -it <pod-name> -- /bin/bash
echo "Hello from Kubernetes" > /usr/local/apache2/htdocs/index.html

πŸ‘‰ Refresh browser β†’ Content changes!

Terminal Output

Working Inside Container


9. Self-Healing (VERY IMPORTANT CONCEPT)

Step 12: Delete One Pod

kubectl delete pod <pod-name>
kubectl get pods -w

πŸ‘‰ Kubernetes automatically: Creates a new pod.

Insight: Deployment ensures: Desired state = maintained.

Terminal Output

Self-Healing


10. Cleanup

kubectl delete deployment apache
kubectl delete service apache

Terminal Output

Cleanup


11. Port Forwarding (Important Theory)

Why it blocks the terminal: Runs a live connection with continuous data flow.

Run in Background:

kubectl port-forward pod/apache-pod 8081:80 &

Manage Processes:

jobs
ps aux | grep port-forward
kill %1
kill <PID>
pkill -f port-forward

Best Practice:

tmux new -s pf
kubectl port-forward pod/apache-pod 8081:80

Detach: Ctrl + b, then d


12. Key Concepts (VERY IMPORTANT FOR EXAM)

Pod vs Deployment

| Feature | Pod | Deployment | |β€”|β€”|β€”| | Lifespan | Temporary | Permanent | | Failure | No recovery | Self-healing | | Management| Manual | Automated |

Port Forwarding

Service

Scaling

Debugging

πŸ‘‰ kubectl describe = Most important command


πŸ”₯ FINAL UNDERSTANDING

This lab teaches:


← Previous Class Next Class β†’ Theory Index