11.Resolve Pod Deployment Issue
Source: Dev.to
Lab Information
A junior DevOps team member encountered difficulties deploying a stack on the Kubernetes cluster. The pod fails to start, presenting errors. Let’s troubleshoot and rectify the issue promptly.
- Pod name:
webserver - Main container:
nginx-container(imagenginx:latest) - Sidecar container:
sidecar-container(imageubuntu:latest)
The goal is to get the pod into a Running state and make the application accessible.
Note: The
kubectlutility onjump_hostis already configured to interact with the Kubernetes cluster.
Initial Inspection
kubectl get pods
kubectl describe pod webserver
If the pod is stuck, delete it before applying a corrected definition:
kubectl delete pod webserver
Create a Corrected Pod Definition
apiVersion: v1
kind: Pod
metadata:
name: webserver
labels:
app: web-app
spec:
containers:
- name: nginx-container
image: nginx:latest # Fixed: removed extra 's'
ports:
- containerPort: 80
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx
- name: sidecar-container
image: ubuntu:latest
command:
- sh
- -c
args:
- while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx
volumes:
- name: shared-logs
emptyDir: {}
Apply the manifest:
kubectl apply -f webserver-fixed.yaml
Verify the Deployment
kubectl get pods
kubectl describe pod webserver
Check logs for each container:
kubectl logs webserver -c nginx-container
kubectl logs webserver -c sidecar-container
Test the web server from inside the pod:
kubectl exec webserver -c nginx-container -- curl -s localhost:80 | head -n 5
If the output shows the expected HTML content, the pod is running correctly and the application is accessible.
Resources & Next Steps
- Full Code Repository: KodeKloud Learning Labs
- More Deep Dives: Whispering Cloud Insights – read other technical articles
- Join Discussion: DEV Community – share your thoughts and questions
- Connect: LinkedIn
Credits
- All labs are from KodeKloud.
- Thank you for providing these valuable resources.