DEV Community

Cover image for 11.Resolve Pod Deployment Issue
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

11.Resolve Pod Deployment Issue

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.

There is a pod named webserver, and the container within it is named nginx-container, its utilizing the nginx:latest image.

Additionally, there's a sidecar container named sidecar-container using the ubuntu:latest image.
Enter fullscreen mode Exit fullscreen mode

Identify and address the issue to ensure the pod is in the running state and the application is accessible.

Note: The kubectl utility on jump_host is configured to interact with the Kubernetes cluster.

Lab Solutions

Step 1: Check the current pod status and details

kubectl get pods
kubectl describe pod webserver
Enter fullscreen mode Exit fullscreen mode


kubectl delete pod webserver
Enter fullscreen mode Exit fullscreen mode
# Create a corrected pod definition
cat > webserver-fixed.yaml <<EOF
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: {}
EOF
Enter fullscreen mode Exit fullscreen mode

Step 2: Apply the corrected configuration

kubectl apply -f webserver-fixed.yaml
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify the pod is running

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Step 4: Check both containers are running

kubectl describe pod webserver
Enter fullscreen mode Exit fullscreen mode

Step 5: Test the nginx container

Check nginx container logs

kubectl logs webserver -c nginx-container
Enter fullscreen mode Exit fullscreen mode

Check sidecar container logs

kubectl logs webserver -c sidecar-container
Enter fullscreen mode Exit fullscreen mode

Step 6: Test application accessibility

Test nginx internally from within the pod

kubectl exec webserver -c nginx-container -- curl -s localhost:80 | head -n 5
Enter fullscreen mode Exit fullscreen mode


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
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)