Following some commands and checks for you troubleshoot a Kubernetes installation.
Checking the installation
- Check if you are able to connect in the cluster. Run:
$ kubectl version
Following an example of expected output.
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"darwin/amd64"} Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:27:17Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
NOTE: The certifications used to connect and be authorized is configured in the ~/.kube/config
- Check the nodes
$ kubectl get nodes
All need to be with the Ready status, otherwise, check if the nodes are configured/joined correctly. This is because there is no pod network for the control plane to communicate. We will install a Container Network.
Following an example off the expected result.
Ensure that the following command, for example, was executed in the nodes after the kubeadm init. For further information see Creating a single control-plane cluster with kubeadm
You can now join any number of machines by running the following on each node
as root:
kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
- Check the namespaces
$ kubectl get namespaces NAME STATUS AGE default Active 2m47s kube-node-lease Active 2m50s kube-public Active 2m50s kube-system Active 2m50s
- Check the kube-system
$ kubectl get pods --namespace kube-system NAME READY STATUS RESTARTS AGE coredns-5644d7b6d9-7qx89 1/1 Running 0 3m49s coredns-5644d7b6d9-8mpgt 1/1 Running 0 3m49s etcd-minikube 1/1 Running 0 2m44s kube-addon-manager-minikube 1/1 Running 0 2m40s kube-apiserver-minikube 1/1 Running 0 2m59s kube-controller-manager-minikube 1/1 Running 0 2m58s kube-proxy-9z2z4 1/1 Running 0 3m49s kube-scheduler-minikube 1/1 Running 0 3m1s storage-provisioner 1/1 Running 0 3m48s
Troubleshooting
- Checking the cluster logs
Unexpected outputs or misbehaving pods can be debugged in various ways. The simplest is to request the pod’s logs. Following an example.
kubectl logs --follow --namespace kube-system kube-apiserver-node-0
NOTE: Logs can be echoed to the screen in real-time with the –follow flag.
- Checking pod logs
Try to get the pod’s logs when its status is not Running
$ kubectl logs --namespace kube-system weave-net-68xm5
NOTE: When a pod has more than one container use the flag –container to inform the container that you would like to check the logs.
- Checking Cluster Events
kubectl get events --watch
Sponsored by: