Commands for performing basic Kubernetes cluster troubleshooting.
(ncn-mw#
) Use one of the following commands to retrieve pod-related logs:
kubectl logs POD_NAME
kubectl logs POD_NAME -c CONTAINER_NAME
(ncn-mw#
) If the pods keeps crashing, open a log for the previous instance using the following command:
kubectl logs -p POD_NAME
(ncn-mw#
) Use the following command to retrieve information about a node’s condition, such as OutOfDisk
, MemoryPressure
, DiskPressure
, etc.
kubectl describe node NODE_NAME
(ncn-mw#
) Use the following command to retrieve information that can help debug pod-related errors.
kubectl describe pod POD_NAME
(ncn-mw#
) Use the following command to list all of the containers in a pod, as shown in the following example:
kubectl describe pod/cray-tftp-6f85767d76-b28gc -n default
(ncn-mw#
) Use the following command to connect to a pod:
kubectl exec -it POD_NAME -c CONTAINER_NAME /bin/sh
(ncn-mw#
) Use the following command to execute a command inside a pod:
kubectl exec POD_NAME ls /
(ncn-mw#
) Use the following command to connect to a currently running container:
kubectl attach POD_NAME -i
(ncn-mw#
) Use the deployment command to scale a deployment up or down, as shown in the following examples:
kubectl scale deployment APPLICATION_NAME --replicas=0
kubectl scale deployment APPLICATION_NAME --replicas=3
(ncn-mw#
) Use the following command to remove components of the deployment’s manifest, such as services, network policies, and more:
kubectl delete –f APPLICATION_NAME.yaml
(ncn-mw#
) Use the following command to reapply the deployment:
kubectl apply –f APPLICATION_NAME.yaml
(ncn-mw#
) Pods can be configured to restart after getting deleted. Use the following command to delete a pod:
kubectl delete pod POD_NAME
CAUTION: It is recommended to be careful while deleting deployments or pods, because doing so can have an effect on other pods.