Failed to "Start Container" while creating pod and gettting CrashLoopBackOff

11/21/2019

I am very new to kubernetes and trying to create a pod with existing docker image. Pod gets created but container attached to it do not run. Can you help me to fix this issue.

Refer earlier answers on stackoverflow but unable to get the answer.

Docker file:

FROM selenium/standalone-firefox-debug:3.141.59-selenium
USER seluser
CMD /opt/bin/entry_point.sh

Image created successfully with Docker file.

Container created successfully and i am able to access the container with vnc viewer.

docker run -d -p 4444:4444 -p 5901:5900 --name=checkcont -it testImage

Note: Do i need to mention 5901:5900 in pod.yml, if yes, can you please give any example that how to mention the different ports for vnc

Getting error "CrashLoopBackOff", when creating the pod using below file

---
 apiVersion: v1
 kind: Pod
 metadata:
   name: hello-test
 spec:
   containers:
   - name: hello-test-cont
     image: testImage
     ports:
     - containerPort: 4444

...

Logs

2019-11-21T09:07:15.834731+00:00 machine-id dockerd-current[18605]: INFO: Leader election disabled.
2019-11-21T09:07:15.999653+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon ensure completed at 2019-11-21T09:07:15+00:00 ==
2019-11-21T09:07:16.000062+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with deprecated label ==
2019-11-21T09:07:16.148533+00:00 machine-id dockerd-current[18605]: error: no objects passed to apply
2019-11-21T09:07:16.149823+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with addon-manager label ==
2019-11-21T09:07:17.509070+00:00 machine-id dockerd-current[18605]: serviceaccount/storage-provisioner unchanged
2019-11-21T09:07:17.510418+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon reconcile completed at 2019-11-21T09:07:17+00:00 ==
2019-11-21T09:07:20.515166+00:00 machine-id dockerd-current[18605]: INFO: Leader election disabled.
2019-11-21T09:07:20.677541+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon ensure completed at 2019-11-21T09:07:20+00:00 ==
2019-11-21T09:07:20.677850+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with deprecated label ==
2019-11-21T09:07:20.814736+00:00 machine-id dockerd-current[18605]: error: no objects passed to apply
2019-11-21T09:07:20.819174+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with addon-manager label ==
2019-11-21T09:07:22.169192+00:00 machine-id systemd[1]: Started libcontainer container 94e63e7fc516e13fd2f68d93ad8b27033578ad6064a4d67b656e4075bc816453.
2019-11-21T09:07:22.171186+00:00 machine-id systemd[1]: Starting libcontainer container 94e63e7fc516e13fd2f68d93ad8b27033578ad6064a4d67b656e4075bc816453.
2019-11-21T09:07:22.187229+00:00 machine-id dockerd-current[18605]: serviceaccount/storage-provisioner unchanged
2019-11-21T09:07:22.188861+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon reconcile completed at 2019-11-21T09:07:22+00:00 ==
2019-11-21T09:07:22.234828+00:00 machine-id dockerd-current[18605]: time="2019-11-21T09:07:22.233811907Z" level=warning msg="Unknown healthcheck type 'NONE' (expected 'CMD') in container 94e63e7fc516e13fd2f68d93ad8b27033578ad6064a4d67b656e4075bc816453"
2019-11-21T09:07:22.243520+00:00 machine-id kubelet[17918]: W1121 09:07:22.243239   17918 docker_sandbox.go:394] failed to read pod IP from plugin/docker: Couldn't find network status for default/hello-test through plugin: invalid network status for
2019-11-21T09:07:22.260932+00:00 machine-id dockerd-current[18605]: time="2019-11-21T09:07:22.260836014Z" level=warning msg="failed to retrieve docker-runc version: unknown output format: runc version 1.0.0-rc2\nspec: 1.0.0-rc2-dev\n"
2019-11-21T09:07:22.261189+00:00 machine-id dockerd-current[18605]: time="2019-11-21T09:07:22.260890502Z" level=warning msg="failed to retrieve docker-init version"
2019-11-21T09:07:22.281343+00:00 machine-id dockerd-current[18605]: time="2019-11-21T09:07:22.281151057Z" level=error msg="containerd: deleting container" error="exit status 1: \"container 94e63e7fc516e13fd2f68d93ad8b27033578ad6064a4d67b656e4075bc816453 does not exist\\none or more of the container deletions failed\\n\""
2019-11-21T09:07:22.286116+00:00 machine-id dockerd-current[18605]: time="2019-11-21T09:07:22.286007527Z" level=warning msg="94e63e7fc516e13fd2f68d93ad8b27033578ad6064a4d67b656e4075bc816453 cleanup: failed to unmount secrets: invalid argument"
2019-11-21T09:07:23.258400+00:00 machine-id kubelet[17918]: W1121 09:07:23.258309   17918 docker_sandbox.go:394] failed to read pod IP from plugin/docker: Couldn't find network status for default/hello-test through plugin: invalid network status for
2019-11-21T09:07:23.265928+00:00 machine-id kubelet[17918]: E1121 09:07:23.265868   17918 pod_workers.go:191] Error syncing pod d148d8b9-83c2-4fa3-aeef-aa52063568f2 ("hello-test_default(d148d8b9-83c2-4fa3-aeef-aa52063568f2)"), skipping: failed to "StartContainer" for "hello-test-cont" with CrashLoopBackOff: "back-off 20s restarting failed container=hello-test-cont pod=hello-test_default(d148d8b9-83c2-4fa3-aeef-aa52063568f2)"
2019-11-21T09:07:24.271600+00:00 machine-id kubelet[17918]: W1121 09:07:24.271511   17918 docker_sandbox.go:394] failed to read pod IP from plugin/docker: Couldn't find network status for default/hello-test through plugin: invalid network status for
2019-11-21T09:07:24.276093+00:00 machine-id kubelet[17918]: E1121 09:07:24.276039   17918 pod_workers.go:191] Error syncing pod d148d8b9-83c2-4fa3-aeef-aa52063568f2 ("hello-test_default(d148d8b9-83c2-4fa3-aeef-aa52063568f2)"), skipping: failed to "StartContainer" for "hello-test-cont" with CrashLoopBackOff: "back-off 20s restarting failed container=hello-test-cont pod=hello-test_default(d148d8b9-83c2-4fa3-aeef-aa52063568f2)"
2019-11-21T09:07:25.193657+00:00 machine-id dockerd-current[18605]: INFO: Leader election disabled.
2019-11-21T09:07:25.342440+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon ensure completed at 2019-11-21T09:07:25+00:00 ==
2019-11-21T09:07:25.342767+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with deprecated label ==
2019-11-21T09:07:25.483283+00:00 machine-id dockerd-current[18605]: error: no objects passed to apply
2019-11-21T09:07:25.490946+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with addon-manager label ==
2019-11-21T09:07:26.855714+00:00 machine-id dockerd-current[18605]: serviceaccount/storage-provisioner unchanged
2019-11-21T09:07:26.857423+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon reconcile completed at 2019-11-21T09:07:26+00:00 ==
2019-11-21T09:07:30.861720+00:00 machine-id dockerd-current[18605]: INFO: Leader election disabled.
2019-11-21T09:07:31.012558+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon ensure completed at 2019-11-21T09:07:31+00:00 ==
2019-11-21T09:07:31.012884+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with deprecated label ==
2019-11-21T09:07:31.163171+00:00 machine-id dockerd-current[18605]: error: no objects passed to apply
2019-11-21T09:07:31.170232+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with addon-manager label ==
2019-11-21T09:07:31.726380+00:00 machine-id dockerd-current[18605]: time="2019-11-21T09:07:31.726164882Z" level=warning msg="failed to retrieve docker-runc version: unknown output format: runc version 1.0.0-rc2\nspec: 1.0.0-rc2-dev\n"
2019-11-21T09:07:31.726701+00:00 machine-id dockerd-current[18605]: time="2019-11-21T09:07:31.726218553Z" level=warning msg="failed to retrieve docker-init version"
2019-11-21T09:07:32.545552+00:00 machine-id dockerd-current[18605]: serviceaccount/storage-provisioner unchanged
2019-11-21T09:07:32.547033+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon reconcile completed at 2019-11-21T09:07:32+00:00 ==
2019-11-21T09:07:35.552154+00:00 machine-id dockerd-current[18605]: INFO: Leader election disabled.
2019-11-21T09:07:35.725415+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon ensure completed at 2019-11-21T09:07:35+00:00 ==
2019-11-21T09:07:35.725775+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with deprecated label ==
2019-11-21T09:07:35.874046+00:00 machine-id dockerd-current[18605]: error: no objects passed to apply
2019-11-21T09:07:35.877087+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with addon-manager label ==
2019-11-21T09:07:37.236668+00:00 machine-id dockerd-current[18605]: serviceaccount/storage-provisioner unchanged
2019-11-21T09:07:37.238603+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon reconcile completed at 2019-11-21T09:07:37+00:00 ==
2019-11-21T09:07:37.265979+00:00 machine-id kubelet[17918]: E1121 09:07:37.264872   17918 pod_workers.go:191] Error syncing pod d148d8b9-83c2-4fa3-aeef-aa52063568f2 ("hello-test_default(d148d8b9-83c2-4fa3-aeef-aa52063568f2)"), skipping: failed to "StartContainer" for "hello-test-cont" with CrashLoopBackOff: "back-off 20s restarting failed container=hello-test-cont pod=hello-test_default(d148d8b9-83c2-4fa3-aeef-aa52063568f2)"
2019-11-21T09:07:40.243249+00:00 machine-id dockerd-current[18605]: INFO: Leader election disabled.
2019-11-21T09:07:40.395096+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon ensure completed at 2019-11-21T09:07:40+00:00 ==
2019-11-21T09:07:40.395435+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with deprecated label ==
2019-11-21T09:07:40.538812+00:00 machine-id dockerd-current[18605]: error: no objects passed to apply
2019-11-21T09:07:40.544479+00:00 machine-id dockerd-current[18605]: INFO: == Reconciling with addon-manager label ==
2019-11-21T09:07:41.902469+00:00 machine-id dockerd-current[18605]: serviceaccount/storage-provisioner unchanged
2019-11-21T09:07:41.904341+00:00 machine-id dockerd-current[18605]: INFO: == Kubernetes addon reconcile completed at 2019-11-21T09:07:41+00:00 ==
"
-- rajjj
docker
kubernetes

3 Answers

11/21/2019

Per the docs about container ports:

...Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed.

The problem you are having according to the logs you posted seems to be that the container cannot be started.

Looking at the events (e.g. kubectl get events --sort-by=.metadata.creationTimestamp) could reveal more info but the problem could be with the image. More specifically - Kubernetes can't find it because it is trying to pull it from the public Docker Hub. Here is why:

Kubernetes pulls container images from a Docker Registry. Per the doc:

You create your Docker image and push it to a registry before referring to it in a Kubernetes pod.

Moreover:

The image property of a container supports the same syntax as the docker command does, including private registries and tags.

You have to push the custom image to a public or private Docker registry and reference the image there in the image property.

This answer should help you to stand up a local Docker registry to use with local Kubernetes cluster.

-- apisim
Source: StackOverflow

11/21/2019

You can specify several ports inside a deployment in a following way:

        ports:
        - containerPort: 7000
          name: one-node
        - containerPort: 7001
          name: two-node
        - containerPort: 7199
          name: bnm
        - containerPort: 9042
          name: qaz

Here is an example of cassandra-statefulset.yaml which uses several ports in the deployment.

As for selenium, there are examples on how to run in on Kubernetes available here.

The Kubernetes selenium-node-firefox-deployment for is as follows:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: selenium-node-firefox
  labels:
    app: selenium-node-firefox
spec:
  replicas: 2
  selector:
    matchLabels:
      app: selenium-node-firefox
  template:
    metadata:
      labels:
        app: selenium-node-firefox
    spec:
      volumes:
      - name: dshm
        emptyDir:
          medium: Memory
      containers:
      - name: selenium-node-firefox
        image: selenium/node-firefox-debug:3.141
        ports:
          - containerPort: 5900
        volumeMounts:
          - mountPath: /dev/shm
            name: dshm
        env:
          - name: HUB_HOST
            value: "selenium-hub"
          - name: HUB_PORT
            value: "4444"
        resources:
          limits:
            memory: "1000Mi"
            cpu: ".5"
-- Crou
Source: StackOverflow

12/4/2019

You can add the ports like this

apiVersion: v1
kind: Pod
metadata:
   name: hello-test
spec:
   containers:
     image: imagename:tag
     ports:
    - containerPort: 4444
      name: hello-test-cont
      protocol: TCP
    - containerPort: 5900
      name: testport
      protocol: TCP

Also make sure to provide the complete image name. if the image already exist on your machine, mention the tag name as well. I was able to create the pod and container with similar file format. Hopefully it should work for you.

-- vish
Source: StackOverflow