Deploy and manage an Apache web server and:
kubectl run apache-pod --image=httpd
kubectl get pods
π Creates a single temporary pod
kubectl describe pod apache-pod
Check for:
kubectl port-forward pod/apache-pod 8081:80
Open: http://localhost:8081 π You will see: βIt works!β

kubectl delete pod apache-pod
Insight: Pod is deleted permanently. β No recovery.
π Pod = Temporary π No self-healing
kubectl create deployment apache --image=httpd
kubectl get deployments
kubectl get pods
π Deployment manages pods.
kubectl expose deployment apache --port=80 --type=NodePort
Access App:
kubectl port-forward service/apache 8082:80
Open: http://localhost:8082

kubectl scale deployment apache --replicas=2
kubectl get pods
π Now:
Observation: Refresh the browser. Requests are handled by different pods.

kubectl set image deployment/apache httpd=wrongimage
kubectl get pods
kubectl describe pod <pod-name>
Error: ImagePullBackOff
kubectl set image deployment/apache httpd=httpd

kubectl exec -it <pod-name> -- /bin/bash
Check Files:
ls /usr/local/apache2/htdocs
π This is where website files are stored.
Exit:
exit
kubectl exec -it <pod-name> -- /bin/bash
echo "Hello from Kubernetes" > /usr/local/apache2/htdocs/index.html
π Refresh browser β Content changes!

kubectl delete pod <pod-name>
kubectl get pods -w
π Kubernetes automatically: Creates a new pod.
Insight: Deployment ensures: Desired state = maintained.

kubectl delete deployment apache
kubectl delete service apache

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
| Feature | Pod | Deployment | |β|β|β| | Lifespan | Temporary | Permanent | | Failure | No recovery | Self-healing | | Management| Manual | Automated |
π kubectl describe = Most important command
This lab teaches:
| β Previous Class | Next Class β | Theory Index |