{"id":594,"date":"2022-04-26T08:45:21","date_gmt":"2022-04-26T08:45:21","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=594"},"modified":"2022-04-26T08:45:21","modified_gmt":"2022-04-26T08:45:21","slug":"troubleshoot-kubernetes-pods","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=594","title":{"rendered":"How To Troubleshoot Kubernetes Pods: Beginners Guide"},"content":{"rendered":"<p>In this blog, you will learn to <strong>troubleshoot <\/strong><a href=\"https:\/\/devopscube.com\/kubernetes-pod\/\" rel=\"noreferrer noopener\"><strong>kubernetes pods<\/strong><\/a> and debug issues associate with the containers inside the pods.<\/p>\n<p>If you are trying to <a href=\"https:\/\/devopscube.com\/become-devops-engineer\/\" rel=\"noreferrer noopener\">become a devops engineer<\/a> with Kubernetes skills, it is essential to understand <strong>pod troubleshooting<\/strong>.<\/p>\n<p>In most cases, you can get the pod error details by describing the pod event. With the error message, you can figure out the cause of the pod failure and rectify it.<\/p>\n<h2 id=\"how-to-troubleshoot-pod-errors\">How to Troubleshoot Pod Errors?<\/h2>\n<p>The first step in troubleshooting a pod is getting the status of the pod.<\/p>\n<pre><code>kubectl get pods<\/code><\/pre>\n<p>The following output shows the error states under the status.<\/p>\n<pre><code>\u279c  kubectl get pods\nNAME                            READY   STATUS                       RESTARTS   AGE\nconfig-service                  0\/1     CreateContainerConfigError   0          20s\nimage-service-fdf74c785-9znfd   0\/1     InvalidImageName             0          30s\nsecret-pod                      0\/1     ContainerCreating            0          15s<\/code><\/pre>\n<p>Now that you know the error type, the next step is to describe the individual pod and browse through the events to pinpoint the reason that is causing the pod error.<\/p>\n<p>For example,<\/p>\n<pre><code>kubectl describe pod config-service<\/code><\/pre>\n<p>Where <code>config-service<\/code> is the pod name. Now let&#8217;s look into detail on how to troubleshoot and debug different types of pod errors.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-8-53.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"501\" height=\"501\"><\/figure>\n<h2 id=\"types-of-pod-errors\">Types of Pod Errors<\/h2>\n<p>Before diving into pod debugging, it&#8217;s essential to understand different types of Pod errors.<\/p>\n<h3 id=\"container-image-errors\">Container &amp; Image Errors<\/h3>\n<p>All these error states are part of the <a href=\"https:\/\/github.com\/kubernetes\/kubernetes\/blob\/master\/pkg\/kubelet\/container\/sync_result.go?ref=devopscube.com\" rel=\"noreferrer noopener\">kubernetes container package<\/a> &amp; <a href=\"https:\/\/github.com\/kubernetes\/kubernetes\/blob\/master\/pkg\/kubelet\/images\/types.go?ref=devopscube.com\" rel=\"noreferrer noopener\">Kubernetes image package<\/a><\/p>\n<p>Following is the list of official <strong>Kubernetes pod errors<\/strong> with error descriptions.<\/p>\n<p><!--kg-card-begin: html--><\/p>\n<table>\n<thead>\n<tr>\n<th>Pod Error Type<\/th>\n<th>Error Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr><\/tr>\n<tr>\n<td><code>ErrImagePull<\/code><\/td>\n<td>If kubernetes is not able to pull the image mentioned in the manifest. <\/td>\n<\/tr>\n<tr>\n<td><code>ErrImagePullBackOff<\/code><\/td>\n<td>Container image pull failed, kubelet is backing off image pull<\/td>\n<\/tr>\n<tr>\n<td><code>ErrInvalidImageName<\/code><\/td>\n<td>Indicates a wrong image name.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrImageInspect<\/code><\/td>\n<td>Unable to inspect the image.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrImageNeverPull<\/code><\/td>\n<td>Specified Image is absent on the node and PullPolicy is set to NeverPullImage<\/td>\n<\/tr>\n<tr>\n<td><code>ErrRegistryUnavailable<\/code><\/td>\n<td>HTTP error when trying to connect to the registry<\/td>\n<\/tr>\n<tr>\n<td><code>ErrContainerNotFound<\/code><\/td>\n<td>The specified container is either not present or not managed by the kubelet, within the declared pod.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrRunInitContainer<\/code><\/td>\n<td>Container initialization failed.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrRunContainer<\/code><\/td>\n<td>Pod\u2019s containers don&#8217;t start successfully due to misconfiguration.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrKillContainer<\/code><\/td>\n<td>None of the pod\u2019s containers were killed successfully.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrCrashLoopBackOff<\/code><\/td>\n<td>A container has terminated. The kubelet will not attempt to restart it.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrVerifyNonRoot<\/code><\/td>\n<td>A container or image attempted to run with root privileges.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrCreatePodSandbox<\/code><\/td>\n<td>Pod sandbox creation did not succeed.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrConfigPodSandbox<\/code><\/td>\n<td>Pod sandbox configuration was not obtained.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrKillPodSandbox<\/code><\/td>\n<td>A pod sandbox did not stop successfully.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrSetupNetwork<\/code><\/td>\n<td>Network initialization failed.<\/td>\n<\/tr>\n<tr>\n<td><code>ErrTeardownNetwork<\/code><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><!--kg-card-end: html--><\/p>\n<p>Now let&#8217;s look at some of the <strong>most common pod errors <\/strong>and how to debug them.<\/p>\n<h3 id=\"troubleshoot-errimagepullbackoff\">Troubleshoot ErrImagePullBackOff<\/h3>\n<pre><code>\u279c  pods kubectl get pods\nNAME                                READY   STATUS             RESTARTS   AGE\nnginx-deployment-599d6bdb7d-lh7d9   0\/1     ImagePullBackOff   0          7m17s<\/code><\/pre>\n<p>If you see <code>ErrImagePullBackOff<\/code> in pod status, it is most likely for the following reasons.<\/p>\n<ol>\n<li>The specified image is not present in the registry.<\/li>\n<li>A typo in the image name or tag.<\/li>\n<li>Image pull access was denied from the given registry due to credential issues.<\/li>\n<li>The contianer image that you are trying to pull doesnt support the worker node architecture.<\/li>\n<\/ol>\n<p>If you check the pod events, you will see the <code>ErrImagePull<\/code> error followed by <code>ErrImagePullBackOff<\/code>. This means the kubelet stops trying to pull the image again and again.<\/p>\n<pre><code>kubectl describe pod &lt;pod-name&gt;<\/code><\/pre>\n<p>Error reference<\/p>\n<pre><code>Warning  Failed     24m (x4 over 25m)    kubelet            Error: ErrImagePull\n  Normal   BackOff    23m (x6 over 25m)    kubelet            Back-off pulling image \"ngasdinx:latest\"\n  Warning  Failed     29s (x110 over 25m)  kubelet            Error: ImagePullBackOff<\/code><\/pre>\n<h3 id=\"troubleshoot-error-invalidimagename\">Troubleshoot Error: InvalidImageName<\/h3>\n<pre><code>\u279c  pods kubectl get pod\nNAME                                READY   STATUS             RESTARTS   AGE\nnginx-deployment-6f597fc4cd-j86mm   0\/1     InvalidImageName   0          7m26s<\/code><\/pre>\n<p>If you specify a wrong image URL in the manifest, you will get the <code>InvalidImageName<\/code> error.<\/p>\n<p>For example, if you have a private container registry and you mention the image name with <code>https<\/code>, it will throw the <code>InvalidImageName<\/code> error. You need to specify the image name without <code>https<\/code><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-15-37.png\" class=\"kg-image\" alt=\"troubleshoot Error: InvalidImageName \" loading=\"lazy\" width=\"536\" height=\"286\"><\/figure>\n<p>If you have trailing slashes in the image name, you will get both <code>InspectFailed<\/code> &amp; <code>InvalidImageName<\/code> errors. You can check it by describing the pod.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-16-41.png\" class=\"kg-image\" alt=\"troubleshoot Error: InvalidImageName  with url slash\" loading=\"lazy\" width=\"578\" height=\"290\"><\/figure>\n<p>Error reference<\/p>\n<pre><code>Warning  InspectFailed  4s (x6 over 42s)  kubelet            Failed to apply default image tag \"registry.hub.docker.com\/library\/\/nginx:latest\": couldn't parse image reference \"registry.hub.docker.com\/library\/\/nginx:latest\": invalid reference format\n  Warning  Failed         4s (x6 over 42s)  kubelet            Error: InvalidImageName<\/code><\/pre>\n<h3 id=\"troubleshoot-runcontainererror\">Troubleshoot RunContainerError<\/h3>\n<pre><code>secret-pod     0\/1     RunContainerError            0 (9s ago)   12s<\/code><\/pre>\n<h3 id=\"pod-configmap-secret-errors-createcontainerconfigerror\">Pod Configmap &amp; Secret Errors [CreateContainerConfigError]<\/h3>\n<p><code>CreateContainerConfigError<\/code> is one of the common errors related to <code>Configmaps<\/code> and <code>Secrets<\/code> in pods.<\/p>\n<p>This normally occurs due to two reasons.<\/p>\n<ol>\n<li>You have the wrong configmap or secret keys referenced as environment variables<\/li>\n<li>The referenced configmap is not available<\/li>\n<\/ol>\n<p>If you describe the pod you will see the following error.<\/p>\n<pre><code>Warning  Failed     3s (x2 over 10s)  kubelet     Error: configmap \"nginx-config\" not found<\/code><\/pre>\n<p>If you have a typo in the key name, you will see the following error in the pod events.<\/p>\n<pre><code>Warning  Failed     2s  kubelet  Error: couldn't find key service-names in ConfigMap default\/nginx-config<\/code><\/pre>\n<p>To rectify this issue,<\/p>\n<ol>\n<li>Ensure the config map is created.<\/li>\n<li>Ensure you have the <strong>correct configmap name &amp; key name<\/strong> added to the env declaration.<\/li>\n<\/ol>\n<p>Let&#8217;s look at the correct example. Here is a configmap where <code>service-name<\/code> is the key that is needed as an env variable inside the pod.<\/p>\n<pre><code>apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: nginx-config\n  namespace: default\ndata:\n  service-name: front-end-service<\/code><\/pre>\n<p>Here is the correct pod definition using the key (<code>service-name<\/code>) &amp; configmap name (<code>nginx-config<\/code>)<\/p>\n<pre><code>apiVersion: v1\nkind: Pod\nmetadata:\n  name: config-service\nspec:\n  containers:\n    - name: nginx\n      image: nginx\n      env:\n        - name: SERVICE\n          valueFrom:\n            configMapKeyRef:\n              name: nginx-config\n              key: service-name<\/code><\/pre>\n<h3 id=\"pod-pending-error\">Pod Pending Error<\/h3>\n<p>To troubleshoot pod pending error, you need to be aware of <a href=\"https:\/\/devopscube.com\/kubernetes-pod-lifecycle\/\">Pod LifeCycle Phases<\/a>. Pending in the first phase of the pod it means, the pod has been created but none of the main containers are running.<\/p>\n<p>To understand the root cause, you can describe the pod and check the events.<\/p>\n<p>For example,<\/p>\n<pre><code>kubectl describe pod &lt;pod-name&gt; -n &lt;namespace&gt;<\/code><\/pre>\n<p>Here is an example, output of a pending pod that shows FailedScheduling due to no node availability. It could happen due to<\/p>\n<pre><code>Events:\n  Type     Reason            Age                  From               Message\n  ----     ------            ----                 ----               -------\n  Warning  FailedScheduling  38s (x24 over 116m)  default-scheduler  no nodes available to schedule pods<\/code><\/pre>\n<p>It could happen due to<\/p>\n<ol>\n<li>Node Less CPU and Memory Resources<\/li>\n<li>No suitable node due to Affinity\/Anti-affinity rules.<\/li>\n<li>Nodes could reject the pod due to Taints and Tolerations<\/li>\n<li>The node might not be ready to schedule the pods.<\/li>\n<li>The pod could not find the volume to be attached.<\/li>\n<\/ol>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/troubleshoot-kubernetes-pods\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Troubleshoot Kubernetes Pods: Beginners Guide \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/troubleshoot-kubernetes-pods\/<\/p>\n","protected":false},"author":1,"featured_media":595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-594","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=594"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/594\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/595"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}