skip to content
Alvin Lucillo

Failed mounted cm as volume

/ 5 min read

In the pod description, nginx-default-conf configmap is mounted under volume nginx-conf-vol on path /etc/nginx/conf.d/default.conf. When you mount a configmap without specifying the specific keys, the keys will be files in the selected path. nginx-default-conf configmap has default.conf key. This means the pod will mount the configmap map on /etc/nginx/conf.d/default.conf and create the default.conf file under it, resulting to /etc/nginx/conf.d/default.conf/default.conf. However, in the nginx image, there’s no default.conf folder, and generally, it should be a file. From this, we can deduce that this is an error on the mounted path value used in the configuration. The correct mount path should be /etc/nginx/conf.d so that when the configmap is mounted, the resulting path will be /etc/nginx/conf.d/default.conf, with default.conf as the key from the configmap. With this, the issue will be fixed.

cluster4-controlplane ~  k get po
NAME                              READY   STATUS             RESTARTS        AGE
nginx-frontend-64f67d769f-zfklb   0/1     CrashLoopBackOff   6 (2m57s ago)   8m58s

cluster4-controlplane ~  k logs nginx-frontend-64f67d769f-zfklb

cluster4-controlplane ~  k describe po nginx-frontend-64f67d769f-zfklb
Name:             nginx-frontend-64f67d769f-zfklb
Namespace:        cka4974
Priority:         0
Service Account:  default
Node:             cluster4-node01/192.168.141.3
Start Time:       Sun, 16 Nov 2025 12:14:57 +0000
Labels:           app=nginx-broken
                  pod-template-hash=64f67d769f
Annotations:      cni.projectcalico.org/containerID: 3118573b503550c1910f21c87c1e1e4c062a65c0b857faf8915851abe0a22fa0
                  cni.projectcalico.org/podIP: 172.17.1.7/32
                  cni.projectcalico.org/podIPs: 172.17.1.7/32
Status:           Running
IP:               172.17.1.7
IPs:
  IP:           172.17.1.7
Controlled By:  ReplicaSet/nginx-frontend-64f67d769f
Containers:
  nginx:
    Container ID:   containerd://36ff15d0a33b179ad4293aa66f9fde4583a861549ca60e594db9e2728148b1fa
    Image:          nginx
    Image ID:       docker.io/library/nginx@sha256:1beed3ca46acebe9d3fb62e9067f03d05d5bfa97a00f30938a0a3580563272ad
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       StartError
      Message:      failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/var/lib/kubelet/pods/b1f5a6c2-56a1-4f94-8a41-b4001a801af7/volumes/kubernetes.io~configmap/nginx-conf-vol" to rootfs at "/etc/nginx/conf.d/default.conf": mount /var/lib/kubelet/pods/b1f5a6c2-56a1-4f94-8a41-b4001a801af7/volumes/kubernetes.io~configmap/nginx-conf-vol:/etc/nginx/conf.d/default.conf (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown
      Exit Code:    128
      Started:      Thu, 01 Jan 1970 00:00:00 +0000
      Finished:     Sun, 16 Nov 2025 12:20:58 +0000
    Ready:          False
    Restart Count:  6
    Environment:    <none>
    Mounts:
      /etc/nginx/conf.d/default.conf from nginx-conf-vol (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-6zkqn (ro)
Conditions:
  Type                        Status
  PodReadyToStartContainers   True
  Initialized                 True
  Ready                       False
  ContainersReady             False
  PodScheduled                True
Volumes:
  nginx-conf-vol:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      nginx-default-conf
    Optional:  false
  kube-api-access-6zkqn:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                    From               Message
  ----     ------     ----                   ----               -------
  Normal   Scheduled  9m11s                  default-scheduler  Successfully assigned cka4974/nginx-frontend-64f67d769f-zfklb to cluster4-node01
  Normal   Pulled     9m10s                  kubelet            Successfully pulled image "nginx" in 140ms (140ms including waiting). Image size: 59774010 bytes.
  Normal   Pulled     9m6s                   kubelet            Successfully pulled image "nginx" in 138ms (138ms including waiting). Image size: 59774010 bytes.
  Normal   Pulled     8m51s                  kubelet            Successfully pulled image "nginx" in 145ms (145ms including waiting). Image size: 59774010 bytes.
  Normal   Pulled     8m23s                  kubelet            Successfully pulled image "nginx" in 136ms (136ms including waiting). Image size: 59774010 bytes.
  Normal   Pulled     7m32s                  kubelet            Successfully pulled image "nginx" in 144ms (144ms including waiting). Image size: 59774010 bytes.
  Normal   Pulled     6m2s                   kubelet            Successfully pulled image "nginx" in 155ms (155ms including waiting). Image size: 59774010 bytes.
  Warning  Failed     6m1s (x6 over 9m7s)    kubelet            Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/var/lib/kubelet/pods/b1f5a6c2-56a1-4f94-8a41-b4001a801af7/volumes/kubernetes.io~configmap/nginx-conf-vol" to rootfs at "/etc/nginx/conf.d/default.conf": mount /var/lib/kubelet/pods/b1f5a6c2-56a1-4f94-8a41-b4001a801af7/volumes/kubernetes.io~configmap/nginx-conf-vol:/etc/nginx/conf.d/default.conf (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown
  Warning  BackOff    4m5s (x25 over 9m5s)   kubelet            Back-off restarting failed container nginx in pod nginx-frontend-64f67d769f-zfklb_cka4974(b1f5a6c2-56a1-4f94-8a41-b4001a801af7)
  Normal   Pulling    3m11s (x7 over 9m10s)  kubelet            Pulling image "nginx"
  Normal   Created    3m11s (x7 over 9m10s)  kubelet            Created container: nginx
  Normal   Pulled     3m11s                  kubelet            Successfully pulled image "nginx" in 137ms (137ms including waiting). Image size: 59774010 bytes.

cluster4-controlplane ~  k get cm
NAME                 DATA   AGE
kube-root-ca.crt     1      9m44s
nginx-default-conf   1      9m44s

cluster4-controlplane ~  k get cm nginx-default-conf -oyaml
apiVersion: v1
data:
  default.conf: |
    server {
    listen       81;
    listen  [::]:81;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
    }
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"default.conf":"server {\nlisten       81;\nlisten  [::]:81;\nserver_name  localhost;\n\n#access_log  /var/log/nginx/host.access.log  main;\n\nlocation / {\n    root   /usr/share/nginx/html;\n    index  index.html index.htm;\n}\n\n#error_page  404              /404.html;\n\n# redirect server error pages to the static page /50x.html\n#\nerror_page   500 502 503 504  /50x.html;\nlocation = /50x.html {\n    root   /usr/share/nginx/html;\n}\n\n# proxy the PHP scripts to Apache listening on 127.0.0.1:80\n#\n#location ~ \\.php$ {\n#    proxy_pass   http://127.0.0.1;\n#}\n\n# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\n#\n#location ~ \\.php$ {\n#    root           html;\n#    fastcgi_pass   127.0.0.1:9000;\n#    fastcgi_index  index.php;\n#    fastcgi_param  SCRIPT_FILENAME  /scripts;\n#    include        fastcgi_params;\n#}\n\n# deny access to .htaccess files, if Apache's document root\n# concurs with nginx's one\n#\n#location ~ /\\.ht {\n#    deny  all;\n#}\n}\n"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"nginx-default-conf","namespace":"cka4974"}}
  creationTimestamp: "2025-11-16T12:14:57Z"
  name: nginx-default-conf
  namespace: cka4974
  resourceVersion: "6323"
  uid: 3ba021af-baa9-4d46-90a9-d995500fad19