# Essential Guide for Beginners

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

## 1. Identify 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

```bash
kubectl -n ${NAMESPACE} get pod  -o wide
```

2. View the yaml configuration of the Pod

```bash
kubectl -n ${NAMESPACE} get pod ${POD_NAME}  -o yaml
```

3. View Pod events

```bash
kubectl  -n ${NAMESPACE} describe pod ${POD_NAME}
```

4. View Pod logs

```bash
kubectl  -n ${NAMESPACE} logs ${POD_NAME} ${CONTAINER_NAME}
```

5. Log into Pod

```bash
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 can help identify the cause. Taking Deployment as an example, this section introduces common commands for Kubernetes Controllers. The command types for other Controllers are consistent with this.

1. View Deployment status

```bash
kubectl -n ${NAMESPACE} get deploy -o wide
```

2. See Deployment yaml configuration

```bash
kubectl -n ${NAMESPACE} get deploy ${DEPLOYMENT_NAME} -o yaml
```

3. View Deployment events

```bash
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

```bash
kubectl  -n ${NAMESPACE} get svc -o wide
```

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

2. View Service events and load balancing information

```bash
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 business.
