kubernetes
  • kubernetes
  • RBAC
  • backstage
  • cpu-mem
  • End2End testing
  • ingress
  • Bookmarks for learning Kubernetes
  • aliases
    • kubectl
  • apache-kafka
    • backup-kasten-k10
  • api-server
    • secure
  • operators
    • Kubernetes Operator Development Bookmarks
    • books
    • api-conventions
    • monitoring
      • refs
    • tutorial
      • concepts
        • capability_model
        • Index
        • watching_resources
  • prep
    • deployment
    • pod
  • quotas
    • refs
    • openshift
      • Resource quotas per project
  • tilt
    • refs
  • wasm
    • 3scale
Powered by GitBook
On this page
  1. prep

deployment

Sure! Here’s a breakdown of Kubernetes deployment troubleshooting questions at basic, intermediate, and advanced levels, with steps for investigating and resolving common issues.


Basic Questions

1. How do you troubleshoot a deployment with pods stuck in a Pending state?

Steps:

  • Describe the Deployment: Run kubectl describe deployment <deployment-name> to see details and events related to the deployment.

  • Describe One of the Pods: Use kubectl describe pod <pod-name> to inspect why the pod is Pending (e.g., resource requests that can't be met, affinity issues).

  • Check Node Availability: Run kubectl get nodes to ensure enough nodes are available and in a Ready state.

  • Review Resource Requests: If resource requests are high, reduce them or increase node capacity.

2. How do you scale a deployment manually?

Solution:

  • Use kubectl scale deployment <deployment-name> --replicas=<number> to set the number of desired replicas.

  • Alternatively, edit the deployment YAML file and update the spec.replicas field, then apply the changes.

3. What can you do if a deployment isn’t updating as expected?

Steps:

  • Check Deployment Status: Use kubectl rollout status deployment <deployment-name> to view rollout progress.

  • Describe the Deployment: Run kubectl describe deployment <deployment-name> to see if any conditions or events are blocking updates.

  • Inspect the ReplicaSet: Sometimes, old replicas persist. Use kubectl get rs to confirm the status of associated replicas, and delete unused ones if necessary.

4. How do you roll back a deployment to a previous version?

Solution:

  • Use kubectl rollout undo deployment <deployment-name> to revert to the last deployment revision.

  • To revert to a specific revision, use kubectl rollout undo deployment <deployment-name> --to-revision=<revision-number>.


Intermediate Questions

1. What steps would you take if pods in a deployment are stuck in a CrashLoopBackOff state?

Steps:

  • Check Pod Logs: Run kubectl logs <pod-name> -c <container-name> to understand why the container is crashing.

  • Describe the Pods: Use kubectl describe pod <pod-name> to check for error events, such as incorrect commands or missing environment variables.

  • Inspect Configuration and Secrets: Verify that configuration maps or secrets referenced by the pod are correctly defined.

  • Adjust Deployment Spec: Fix any issues identified in the logs or description, such as incorrect commands, and reapply the deployment.

2. How do you troubleshoot a deployment with pods that are not reaching a Ready state?

Steps:

  • Describe the Pods: Run kubectl describe pod <pod-name> to see if there are issues with readiness or liveness probes.

  • Check Logs for Errors: Use kubectl logs <pod-name> to identify any issues that prevent the pod from becoming ready.

  • Verify Probe Configuration: Make sure readiness and liveness probes are correctly configured with accurate paths, ports, and response times.

  • Check Resource Limits: Ensure the pod has adequate resources, as insufficient resources may cause readiness probes to fail.

3. How do you pause and resume a deployment?

Solution:

  • To pause a deployment, use kubectl rollout pause deployment <deployment-name>. This halts further updates to the deployment.

  • To resume, use kubectl rollout resume deployment <deployment-name>, which allows updates to continue as configured.

4. How do you check the rollout history of a deployment?

Solution:

  • Use kubectl rollout history deployment <deployment-name> to see past rollout revisions and identify changes across versions.

  • To see details of a specific revision, use kubectl rollout history deployment <deployment-name> --revision=<revision-number>.


Advanced Questions

1. How do you troubleshoot high resource usage across all replicas in a deployment?

Steps:

  • Monitor Deployment Metrics: Use kubectl top pod -l app=<app-label> to check aggregate resource usage for pods managed by the deployment.

  • Describe the Pods: Check the configuration of each pod to ensure resource requests and limits are appropriately set.

  • Profile Application: If possible, use APM tools to identify specific code paths causing high usage.

  • Scale the Deployment: If each pod’s resource consumption is expected but high, consider horizontally scaling the deployment.

2. How do you identify and troubleshoot an issue where a deployment is constantly redeploying?

Steps:

  • Describe the Deployment: Run kubectl describe deployment <deployment-name> to check for repeated triggers or configuration issues.

  • Inspect the Events: Look at events for Updated or Scheduled entries to identify if the deployment spec is constantly changing.

  • Check ConfigMaps and Secrets: If the deployment depends on a ConfigMap or Secret and they are updated frequently, it will trigger redeployments. Avoid frequent updates or use immutable ConfigMaps/Secrets.

  • PodTemplateHash Annotation: Verify that the pod-template-hash annotation isn’t changing unnecessarily. This can occur if there’s a setting like imagePullPolicy: Always.

3. How do you manage and troubleshoot deployments across multiple environments (e.g., dev, staging, production)?

Steps:

  • Use Namespaces: Create separate namespaces for each environment (e.g., dev, staging, prod) and manage deployments independently within each.

  • Use Labels and Selectors: Apply environment-specific labels (env=dev, env=prod) to each deployment and use label selectors for targeting resources.

  • Parameterize Configurations: Use tools like Helm or Kustomize to template deployment manifests with environment-specific configurations.

  • Review Resource Quotas: Ensure each namespace has resource quotas to prevent overconsumption in one environment from affecting others.

4. How do you troubleshoot networking issues where a deployment cannot reach external services?

Steps:

  • Check Network Policies: Confirm that no NetworkPolicy is blocking egress traffic from the deployment’s pods.

  • DNS Resolution: Use kubectl exec <pod-name> -- nslookup <service-hostname> to test DNS resolution from within the pod.

  • Service Configuration: Ensure that services used by the deployment (e.g., ClusterIP or LoadBalancer) are correctly configured and accessible.

  • Verify Egress Access: If your cluster uses an egress controller or firewall, confirm that it allows traffic to the destination.

5. How do you perform a zero-downtime deployment and troubleshoot issues that arise during rollout?

Steps:

  • Set Up Rolling Update Strategy: Use the rolling update strategy in the deployment spec (strategy.type: RollingUpdate) to ensure gradual pod replacement.

  • Configure Max Surge and Max Unavailable: Set maxSurge and maxUnavailable parameters in the deployment to control the number of new pods created and old pods deleted during the update.

  • Monitor Rollout Status: Use kubectl rollout status deployment <deployment-name> to track the progress and identify issues.

  • Check Health Probes: Ensure readiness and liveness probes are properly set to avoid traffic being sent to unready pods.

6. How can you troubleshoot issues with deployment scaling when the HPA (Horizontal Pod Autoscaler) is not working as expected?

Steps:

  • Check HPA Status: Run kubectl get hpa to see the current status, metrics, and target replica count.

  • Verify Metrics Server: Ensure the metrics server is running and providing data, as HPA relies on it for metrics. Use kubectl top nodes to verify metrics are available.

  • Describe HPA: Run kubectl describe hpa <hpa-name> to see if there are errors or configuration issues (e.g., missing or misconfigured resource metrics).

  • Inspect Deployment Resources: Ensure the deployment’s resource requests and limits are set up correctly. The HPA only works if requests are defined on the deployment.


These scenarios will help you develop troubleshooting skills for real-world Kubernetes deployments and tackle both standard and complex deployment issues. Each approach uses native Kubernetes commands and configuration best practices, with an emphasis on resource management, monitoring, and diagnostics for production-grade deployments.

PreviousprepNextpod

Last updated 7 months ago