DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Day 59: Troubleshoot Deployment Issues in Kubernetes

Last week, the Nautilus DevOps team deployed a redis app on Kubernetes cluster, which was working fine so far. This morning one of the team members was making some changes in this existing setup, but he made some mistakes and the app went down. We need to fix this as soon as possible. Please take a look.

The deployment name is redis-deployment. The pods are not in running state right now, so please look into the issue and fix the same.


Step 1: Identify the Issue

kubectl get deployments
kubectl get pods
kubectl describe deployment redis-deployment
Enter fullscreen mode Exit fullscreen mode

Issues Found:

  • Pod stuck in ContainerCreating status
  • Image: redis:alpin (invalid, should be redis:alpine)
  • ConfigMap: redis-conig (misspelled, should be redis-config)

Step 2: Delete the Faulty Deployment

kubectl delete deployment redis-deployment
Enter fullscreen mode Exit fullscreen mode

Step 3: Create Corrected YAML

cat > redis-deployment-fixed.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deployment
  labels:
    app: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis-container
        image: redis:alpine
        ports:
        - containerPort: 6379
        resources:
          requests:
            cpu: 300m
        volumeMounts:
        - mountPath: /redis-master-data
          name: data
        - mountPath: /redis-master
          name: config
      volumes:
      - name: data
        emptyDir: {}
      - name: config
        configMap:
          name: redis-config
EOF
Enter fullscreen mode Exit fullscreen mode

Step 4: Apply the Corrected Deployment

kubectl apply -f redis-deployment-fixed.yaml
Enter fullscreen mode Exit fullscreen mode

Step 5: Verify the Fix

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

Output:

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
redis-deployment   1/1     1            1           31s
Enter fullscreen mode Exit fullscreen mode
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Output:

NAME                                READY   STATUS    RESTARTS   AGE
redis-deployment-5476b4ddd6-f7txp   1/1     Running   0          31s
Enter fullscreen mode Exit fullscreen mode

Key Learnings

Common Issues and Fixes

Issue Symptom Fix
Invalid image name ContainerCreating Use correct image name and tag
Misspelled ConfigMap ContainerCreating Match ConfigMap name exactly
Missing ConfigMap ContainerCreating Create the ConfigMap
Resource limits Pending or CrashLoopBackOff Adjust resource requests/limits

Troubleshooting Commands

Command Purpose
kubectl get deployments Check deployment status
kubectl get pods Check pod status
kubectl describe deployment <name> Detailed deployment info
kubectl describe pod <name> Detailed pod info
kubectl logs <pod-name> View pod logs
kubectl get events View cluster events
kubectl rollout status deployment <name> Check rollout status

Top comments (0)