Reference Link:
https://upessocs.github.io/#dir=/Lectures/Containerization%20and%20DevOps/Theory/003%20Unit%203/&file=306%20Apache%20webserver%20deploy%20using%20kubernetis.md
Deploy and manage a simple Apache-based web server using Kubernetes and perform the following tasks:





Command:
kubectl run apache-pod --image=httpd
Explanation:
This command creates a Pod named apache-pod using the Apache (httpd) image.
Command:
kubectl get pods
Explanation:
This command checks the status of the Pod. Initially, it shows ContainerCreating, and after some time it changes to Running.
Command:
kubectl port-forward pod/apache-pod 8081:80
Explanation:
This command forwards local port 8081 to container port 80, allowing access to the web application.
Open in Browser:
http://localhost:8081
Output:
The Apache default page (โIt works!โ) is displayed.
Command:
kubectl create deployment apache --image=httpd
Explanation:
This command creates a Deployment named apache, which manages Pods and supports scaling.
Command:
kubectl get deployments
kubectl get pods
Explanation:
These commands verify that the Deployment is created and Pods are running.
Command:
kubectl scale deployment apache --replicas=3
Explanation:
This command increases the number of Pods to 3, improving availability and load handling.
Command:
kubectl get pods
Explanation:
This confirms that multiple Pods (3 replicas) are running.
Command:
kubectl expose deployment apache --port=80 --type=NodePort
Explanation:
This exposes the Deployment as a Service, enabling external access.
Command:
kubectl set image deployment/apache httpd=wrongimage
Explanation:
This intentionally sets an incorrect image to simulate a failure scenario.
Command:
kubectl get pods
Explanation:
Some Pods enter ErrImagePull or ImagePullBackOff, indicating failure to fetch the image.
Command:
kubectl describe pod <pod-name>
Explanation:
This shows detailed Pod information. The Events section reveals the image pull failure.
Command:
kubectl set image deployment/apache httpd=httpd
Explanation:
This restores the correct image and resolves the issue.
Command:
kubectl get pods
Explanation:
All Pods return to the Running state, confirming successful recovery.
The Apache web application was successfully deployed, accessed, scaled, debugged, and restored using Kubernetes.
ErrImagePull help identify issues