Common Kubernetes Resource Management Issues
This guide covers frequently encountered issues when managing Kubernetes resources and provides practical solutions to resolve them.
Pod Issues
Section titled “Pod Issues”Pods Stuck in Pending State
Section titled “Pods Stuck in Pending State”Symptoms:
- Pods remain in
Pendingstatus indefinitely - Events show resource constraints or scheduling issues
Diagnostic Commands:
# Check pod status and eventskubectl describe pod <pod-name> -n <namespace>
# Check node resource availabilitykubectl describe nodes | grep -A 5 "Allocated resources"Common Causes and Solutions:
-
Insufficient Resources
- Nodes don’t have enough CPU/memory to schedule the pod
Terminal window # Check resource requests vs node capacitykubectl describe nodes | grep -A 10 "Capacity"# Adjust pod resource requestskubectl patch deployment <deployment-name> -n <namespace> --type=json -p='[{"op":"replace","path":"/spec/template/spec/containers/0/resources/requests","value":{"cpu":"100m","memory":"256Mi"}}]' -
Node Selector/Affinity Constraints
- Pod has node selectors that can’t be satisfied
Terminal window # Check node labelskubectl get nodes --show-labels# Modify node selector if neededkubectl patch deployment <deployment-name> -n <namespace> --type=json -p='[{"op":"remove","path":"/spec/template/spec/nodeSelector"}]' -
PVC Binding Issues
- Pod requires PVC that can’t be bound
Terminal window # Check PVC statuskubectl get pvc -n <namespace>kubectl describe pvc <pvc-name> -n <namespace>
Pods Stuck in Terminating State
Section titled “Pods Stuck in Terminating State”Symptoms:
- Pod shows
Terminatingstatus for an extended period kubectl delete podhangs
Solutions:
# Force delete the podkubectl delete pod <pod-name> -n <namespace> --force --grace-period=0
# If pod has finalizers, remove themkubectl patch pod <pod-name> -n <namespace> --type='json' -p='[{"op":"remove","path":"/metadata/finalizers"}]'CrashLoopBackOff Errors
Section titled “CrashLoopBackOff Errors”Symptoms:
- Pod status shows
CrashLoopBackOff - Container repeatedly restarts
Diagnostic Commands:
# Check pod logskubectl logs <pod-name> -n <namespace> --previous
# Check pod eventskubectl describe pod <pod-name> -n <namespace>Solutions:
- Fix application errors shown in logs
- Ensure resource limits are adequate:
Terminal window kubectl patch deployment <deployment-name> -n <namespace> --type=json -p='[{"op":"replace","path":"/spec/template/spec/containers/0/resources/limits","value":{"cpu":"1","memory":"1Gi"}}]' - Check for volume mount issues:
Terminal window kubectl describe pod <pod-name> -n <namespace> | grep -A 10 "Volumes:"
Deployment Issues
Section titled “Deployment Issues”Deployment Not Creating Pods
Section titled “Deployment Not Creating Pods”Symptoms:
- Deployment exists but no pods are created
- Replica count shows 0/N available
Diagnostic Commands:
# Check deployment statuskubectl describe deployment <deployment-name> -n <namespace>
# Check replica setskubectl get rs -n <namespace> -l app=<deployment-selector>Solutions:
-
Check for admission controller issues:
Terminal window kubectl get validatingwebhookconfigurationskubectl get mutatingwebhookconfigurations -
Verify pod spec is valid:
Terminal window kubectl apply --validate=true --dry-run=client -f deployment.yaml -
Check for PodDisruptionBudget conflicts:
Terminal window kubectl get pdb -n <namespace>
Deployment Stuck on Rolling Update
Section titled “Deployment Stuck on Rolling Update”Symptoms:
- Deployment shows partial rollout
- New pods don’t become ready
Solutions:
-
Check readiness probe failures:
Terminal window kubectl describe pod <new-pod-name> -n <namespace> -
Adjust rollout strategy:
Terminal window kubectl patch deployment <deployment-name> -n <namespace> --type=json -p='[{"op":"replace","path":"/spec/strategy","value":{"type":"Recreate"}}]' -
Rollback to previous version:
Terminal window kubectl rollout undo deployment/<deployment-name> -n <namespace>
Service and Networking Issues
Section titled “Service and Networking Issues”Service Not Routing Traffic
Section titled “Service Not Routing Traffic”Symptoms:
- Pods are running but service doesn’t route traffic
- Endpoint connections time out
Diagnostic Commands:
# Check service and endpointskubectl describe service <service-name> -n <namespace>kubectl get endpoints <service-name> -n <namespace>
# Verify label selectorskubectl get pods -n <namespace> -l <service-selector>Solutions:
-
Fix selector mismatch:
Terminal window # Update service selector to match pod labelskubectl patch service <service-name> -n <namespace> --type=json -p='[{"op":"replace","path":"/spec/selector","value":{"app":"<correct-label>"}}]' -
Check pod readiness:
Terminal window kubectl get pods -n <namespace> -o wide -
Test network connectivity:
Terminal window kubectl run test-$RANDOM --rm -it --image=busybox -n <namespace> -- wget -O- <service-name>:<port>
Ingress Not Working
Section titled “Ingress Not Working”Symptoms:
- Service works internally but Ingress doesn’t route external traffic
- Ingress controller logs show errors
Solutions:
-
Verify Ingress resource:
Terminal window kubectl describe ingress <ingress-name> -n <namespace> -
Check Ingress controller logs:
Terminal window kubectl logs -n <ingress-controller-namespace> -l app=<ingress-controller> --tail=100 -
Verify TLS certificate if using HTTPS:
Terminal window kubectl get secret <tls-secret-name> -n <namespace>
Volume and Storage Issues
Section titled “Volume and Storage Issues”PersistentVolumeClaim Stuck in Pending
Section titled “PersistentVolumeClaim Stuck in Pending”Symptoms:
- PVC remains in
Pendingstate - Pods requiring the PVC also stay in
Pending
Diagnostic Commands:
# Check PVC statuskubectl describe pvc <pvc-name> -n <namespace>
# Check storage classeskubectl get storageclassSolutions:
-
Verify storage class exists and is default:
Terminal window kubectl get sc -o yaml -
Check storage provisioner is running:
Terminal window kubectl get pods -n kube-system | grep provisioner -
Create PV manually if using static provisioning:
Terminal window kubectl apply -f persistent-volume.yaml
Volume Mount Failures
Section titled “Volume Mount Failures”Symptoms:
- Pods fail to start with volume-related errors
- Events show “unable to mount volume”
Solutions:
-
Check volume types and paths:
Terminal window kubectl describe pod <pod-name> -n <namespace> | grep -A 15 "Volumes:" -
Verify permissions on host paths:
Terminal window # For hostPath volumes on specific nodekubectl debug node/<node-name> -it --image=ubuntu -- bashls -la /path/on/host -
Check if the PV was deleted:
Terminal window kubectl get pv | grep <pv-name>
ConfigMap and Secret Issues
Section titled “ConfigMap and Secret Issues”ConfigMap or Secret Changes Not Reflected in Pods
Section titled “ConfigMap or Secret Changes Not Reflected in Pods”Symptoms:
- Updated ConfigMap or Secret doesn’t affect running pods
- Applications still use old configurations
Solutions:
-
Restart dependent pods:
Terminal window kubectl rollout restart deployment <deployment-name> -n <namespace> -
Use latest Kubernetes best practices:
Terminal window # Add checksum annotation to trigger automatic restartsCHECKSUM=$(kubectl get cm <configmap-name> -n <namespace> -o yaml | sha256sum)kubectl patch deployment <deployment-name> -n <namespace> --type=json -p="[{\"op\":\"add\",\"path\":\"/spec/template/metadata/annotations/checksum\",\"value\":\"${CHECKSUM}\"}]" -
Use ConfigMap subPath with caution - it won’t auto-update
Resource Quota and Limit Issues
Section titled “Resource Quota and Limit Issues”Namespace Resource Quota Exceeded
Section titled “Namespace Resource Quota Exceeded”Symptoms:
- New resources can’t be created
- Events show “exceeded quota” errors
Diagnostic Commands:
# Check resource quota usagekubectl describe resourcequota -n <namespace>Solutions:
-
Identify resource hogs:
Terminal window kubectl top pod -n <namespace> -
Adjust quota limits:
Terminal window kubectl edit resourcequota <quota-name> -n <namespace> -
Clean up unused resources:
Terminal window kubectl get all -n <namespace>
LimitRange Conflicts
Section titled “LimitRange Conflicts”Symptoms:
- Pods fail validation
- Events show limit range errors
Solutions:
# Check limit range settingskubectl get limitrange -n <namespace> -o yaml
# Adjust deployment resourceskubectl patch deployment <deployment-name> -n <namespace> --type=json -p='[{"op":"replace","path":"/spec/template/spec/containers/0/resources","value":{"requests":{"memory":"64Mi","cpu":"50m"},"limits":{"memory":"128Mi","cpu":"100m"}}}]'