Skip to Content
Product IntroductionEssential Guide for Beginners

Essential Guide for Beginners

Kubernetes provides a series of commands to assist in debugging and pinpointing issues. This section lists some common commands to help application administrators troubleshoot and resolve issues quickly.

1. Identifying Problems

Before addressing any issues, it’s crucial to determine the type of problem: whether it involves a Pod, Service, or Controller (e.g., Deployment, StatefulSet). Use appropriate commands based on the identified issue to investigate the root cause.

2. Common Pod Commands

If a Pod is in a Pending state, crashes repeatedly, or cannot accept traffic, the following commands can help identify the underlying issue:

  1. Get Pod status
kubectl -n ${NAMESPACE} get pod -o wide
  1. View the yaml configuration of the Pod
kubectl -n ${NAMESPACE} get pod ${POD_NAME} -o yaml
  1. View Pod events
kubectl -n ${NAMESPACE} describe pod ${POD_NAME}
  1. View Pod logs
kubectl -n ${NAMESPACE} logs ${POD_NAME} ${CONTAINER_NAME}
  1. Log into Pod
kubectl -n ${NAMESPACE} exec -it ${POD_NAME} /bin/bash

3. Common Controller Commands

The Controller is responsible for Pod’s lifecycle management. If a Pod fails to register, the Controller commands can help identify the cause. Here’s how to use common commands for a Deployment as an example:

  1. View Deployment status
kubectl -n ${NAMESPACE} get deploy -o wide
  1. See Deployment yaml configuration
kubectl -n ${NAMESPACE} get deploy ${DEPLOYMENT_NAME} -o yaml
  1. View Deployment events
kubectl -n ${NAMESPACE} describe deployment ${DEPLOYMENT_NAME}

4. Common Service Commands

Services define how to access a set of Pods. If the application is inaccessible, use the following Service commands to diagnose the issue:

  1. View Service status
kubectl -n ${NAMESPACE} get svc -o wide

This command provides details about the Service type, internal and external IPs, exposed ports, and Selector information.

  1. View Service events and load balancing information
kubectl -n ${NAMESPACE} describe svc ${SERVICE_NAME} Name: example-app Namespace: default Labels: app=example-app Annotations: <none> Selector: app=example-app Type: ClusterIP IP: 10.2.192.27 Port: web 8080/TCP TargetPort: 8080/TCP Endpoints: 192.168.59.207:8080,192.168.75.87:8080,192.168.84.90:8080 Session Affinity: None Events: <none>

By using this command, you can check the Endpoints information of the Service. If the Endpoints are empty, it indicates a configuration error, preventing the Service from forwarding traffic to the corresponding Pods. Ensure that the Port and TargetPort settings align with the actual exposed ports of your application.