... Playbook #24

K8s Deployment Replica Check

This incident type in Kubernetes signals disparities between the intended and actual numbers of replica pods, This playbook help in finding a potential misalignment with deployment specifications. It prompts a thorough investigation and corrective measures to realign deployments with defined specifications, ensuring consistency and reliability in cluster operations.

List all k8s deployments in the affected namespace deployment replica check
                              
kubectl get deployments -A -o json | jq '.items[] | select(.status.availableReplicas != .spec.replicas) | {namespace: .metadata.namespace, name: .metadata.name, currentReplicas: .status.availableReplicas, desiredReplicas: .spec.replicas}'
                              
                            
Check and list all deployment replica check affected namespace
                              
kubectl get deployments -A -o json | jq '.items[] | select(.status.availableReplicas != .spec.replicas) | {namespace: .metadata.namespace, name: .metadata.name, currentReplicas: .status.availableReplicas, desiredReplicas: .spec.replicas}' | grep -w namespace
                              
                            
Check and list all the events in affected k8s namespaces
                              
failed_deployments=$(kubectl get deployments -A -o json | jq -r '.items[] | select(.status.availableReplicas != .spec.replicas) | .metadata.namespace + "/" + .metadata.name') && for deployment in $failed_deployments; do     namespace=$(echo "$deployment" | cut -d '/' -f1);     deployment_name=$(echo "$deployment" | cut -d '/' -f2)  echo "Events for deployment $deployment_name in namespace $namespace:";  kubectl get events --namespace="$namespace";     echo "------------------------"; done