Logging, Monitoring & Troubleshooting
Understanding Resource Monitoring
kubectl getcan be used on any resource and shows generic resource health.- If metrics are collected, use
kubectl top podsandkubectl top nodesto get performance-related information about Pods and Nodes. - Consider using advanced tools like Prometheus and Grafana for more details about application usage.
Understanding Troubleshooting Flow
- Resources are first created in the Kubernetes etcd database.
- Use
kubectl describeandkubectl eventsto see how that has been going. - After adding the resources to the database, the Pod application is started on the nodes where it is scheduled.
- Before it can be started, the Pod image needs to be fetched:
- Use
sudo crictl imagesto get a list
- Use
- Once the application is started, use
kubectl logsto read the output of the application. - On running applications, use an interactive shell for further investigation.
Troubleshooting Pods
- The first step is to use
kubectl get, which will give a generic overview of Pod states - A Pod can be in any of the following states:
- Pending: the Pod has been created in etcd, but is waiting for an eligible node
- Running: the Pod is in a healthy state
- Succeeded: the Pod has done its work and there is no need to restart it
- Failed: one or more containers in the Pod have ended with an error code and will not be restarted
- Unknown: the state could not be obtained, often related to network issues
- Completed: the Pod has run to completion
- CrashLoopBackOff: one or more containers in the Pod have generated an error, but the scheduler is still trying to run them
Investigating Resource Problems
- If
kubectl getindicates that there is an issue, the next step is to usekubectl describeto get more information. kubectl describeshows API information about the resource and often has good indicators of what is going wrong.- If
kubectl describeshows that a Pod has an issue starting its primary container, usekubectl logsto investigate the application logs. - If the Pod is running, but not behaving as expected, open an interactive shell on the Pod for further troubleshooting:
kubectl exec -it mypod -- sh
Troubleshooting Cluster Nodes
- Use
kubectl cluster-infofor a generic impression of cluster health. - Use
kubectl cluster-info dumpfor (too much) information coming from all the cluster log files. kubectl get nodeswill give a generic overview of node health.kubectl get pods -n kube-systemshows Kubernetes core services running on the control node.kubectl describe node nodenameshows detailed information about nodes, check the "Conditions" section for operational information.sudo systemctl status kubeletwill show current status information about the kubelet.sudo systemctl restart kubeletallows you to restart it.sudo openssl x509 -in /var/lib/kubelet/pki/kubelet.crt -textallows you to verify kubelet certificates and verify they are still valid.The kube-proxy Pods are running to ensure connectivity with worker nodes, use
kubectl get pods -n kube-systemfor an overview.
Understanding Application Access
- To access applications running in the Pods, Services and Ingress are used.
- The Service resource uses a selector label to connect to Pods with a matching label.
- The Ingress resource connects to a Service and picks up its selector label to connect to the backend Pods directly.
- To troubleshoot application access, check the labels in all of these resources.
Page Source