Kubernetes configmap crash pod

4/30/2018

I create configmap with the command line kubectl like this:

 kubectl create configmap nginx-config --from-file=./site.conf

In my site.conf I have a simple nginx conf:

server {
    listen       80;

    index index.php index.html;
    location / {
        try_files $uri $uri/ /index.php?$args;
        access_log off;
        expires max;
    }
}

In my nginx-pod.yaml I have normal pod setup:

apiVersion: v1
kind: Pod
metadata:
  name: www
  labels:
    app: nginx
spec:
  containers:
    - name: proxy
      image: nginx
      ports:
        - containerPort: 80
      volumeMounts:
        - mountPath: /etc/nginx/conf.d
          name: nginx-config
  volumes:
    - name: nginx-config
      configMap:
        name: nginx-config

When a start the pod like this:

kubectl create -f nginx-pod.yaml

My pod is create but his status CrashLoopBackOff 2-3 sec later but if I remove this line:

volumeMounts:
        - mountPath: /etc/nginx/conf.d
          name: nginx-config
  volumes:
    - name: nginx-config
      configMap:
        name: nginx-config

I have no problems.

-- john
kubectl
kubernetes
minikube

2 Answers

4/30/2018

Something else is messing you out. I've just literally copied your conf and yaml file (except running it with -n test-namespace for separation) and it worked flawlessly.

Running ok, jumped to pod, and site.conf is happily mounted in /etc/nginx/conf.d folder as intended. Baremetal k8s version I'm using is 1.9.2 and configuration wise this is correct.

Edit: Just tried it with minikube on Mac as well (client 1.9.3 server 1.9.0) and it also just works (not even namespaces there, exactly your described steps).

Can you see logs for scheduler/api or pod in failed state? Maybe it can shed more light to what is preventing it from starting? You don't have RBAC misconfigured or something across namespaces that would prevent config map from being read?

-- Const
Source: StackOverflow

5/1/2018

I have had the seem ploblem recently in the problem was the site.conf. Your pod load your configmap correctly pour when nginx load her conf your nginx crash end your pod crash . Check your site.conf end add de default value like this

server {
    listen 80;
    listen [::]:80;

    root /var/www/html/quickstart/public;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name example.com www.example.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
}
--
Source: StackOverflow