We’ve discussed troubleshooting running containers, but what if the containers fail to start for some reason?
Let’s look at the following example:
$ kubectl run nginx-1 –image=nginx-1
Now, let’s try to get the pod and see for ourselves:
$ kubectl | get | pod | nginx-1 | ||
NAME | READY | STATUS | RESTARTS | AGE | |
nginx-1 | 0/1 | ImagePullBackOff | 0 | 25s |
Oops! There is some error now, and the status is ImagePullBackOff. Well, it seems like there is some
issue with the image. While we understand that the issue is with the image, we want to understand the
real issue, so for further information on this, we can describe the pod using the following command:
$ kubectl describe pod nginx-1
Now, this gives us a wealth of information regarding the pod, and if you look at the events section, you will find a specific line that tells us what is wrong with the pod:
Warning Failed 60s (x4 over 2m43s) kubelet Failed to pull image “nginx-1”: rpc error: code = Unknown desc = failed to pull and unpack image “docker.io/library/ nginx-1:latest”: failed to resolve reference “docker.io/library/nginx-1:latest”: pull
access denied, repository does not exist or may require authorization: server message:
insufficient_scope: authorization failed
So, this one is telling us that either the repository does not exist, or the repository exists but it is private, and hence authorization failed.
Tip
You can use kubectl describe for most Kubernetes resources. It should be the first command you use while troubleshooting issues.
Since we know that the image does not exist, let’s change the image to a valid one. We must delete the pod and recreate it with the correct image to do that.
To delete the pod, run the following command:
$ kubectl delete pod nginx-1
To recreate the pod, run the following command:
$ kubectl run nginx-1 –image=nginx
Now, let’s get the pod; it should run as follows:
$ kubectl | get pod | nginx-1 | ||
NAME | READY | STATUS | RESTARTS | AGE |
nginx-1 | 1/1 | Running | 0 | 42s |
The pod is now running since we have fixed the image issue.
So far, we’ve managed to run containers using pods, but pods are very powerful resources that help you manage containers. Kubernetes pods provide probes to ensure your application’s reliability. We’ll have a look at this in the next section.