CrashLoopBackOff when args are added in Kubernetes

12/16/2016

This deployment is fine until I add args (added below) to the deployment. I can't figure out why it would turn into a CrashLoopError when adding simple args. I even tried to echo Hello World and it still results in a CrashLoopError.

There are no logs and when I describe the pod it shows:

Warning     FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "nginx" with CrashLoopBackOff: "Back-off 10s restarting failed container=nginx pod=nginx-2247906467-r9znh_dave-testing(98c3999e-c39b-11e6-936e-0050568b4a68)"

and here is the YAML:

- kind: Deployment
  apiVersion: extensions/v1beta1
  metadata:
    name: nginx
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          name: nginx
          version: "1.9"
      spec:
        containers:
        - name: nginx
          imagePullPolicy: Always
          image: "nginx:1.9"
          ports:
          - containerPort: 80
          args:
          - "echo $NGINX_CONF > /etc/nginx/nginx.conf"
          env:
          - name: NGINX_CONF
            valueFrom:
              secretKeyRef:
                name: confs
                key: nginx
-- dgallant
docker
kubernetes

1 Answer

1/15/2017

Here is a working version of Kubernetes Pod with nginx alpine docker image:

apiVersion: v1
kind: Pod
metadata:
  name: frontend-nginx-pod
  labels:
    app: nginx-test
spec:
  containers:
    - name: nginx
      image: nginx:1.11.6-alpine
      ports:
        - containerPort: 80
          name: "http-server"
      args:
      - /bin/sh
      - -c
      - echo "hello" > /usr/share/nginx/html/index.html && nginx "-g daemon off;"

I was getting the same error without listing args as above.

-- Ewa
Source: StackOverflow