Kubernetes pod is not starting

9/2/2017

kubectl run ls --image=tomcat --command -- pwd

Using following command to start a pod.

Here is result of using kubectl decribe pods

Events:

  FirstSeen     LastSeen        Count   From                    SubObjectPath           Type        Reason
        Message
  ---------     --------        -----   ----                    -------------           --------    ------
        -------
  26s           26s             1       default-scheduler                               Normal      Scheduled
Successfully assigned ls-2648590517-hvnrr to minikube
  26s           26s             1       kubelet, minikube                               Normal      SuccessfulMountVolume       MountVolume.SetUp succeeded for volume "default-token-3px95"
  25s           20s             2       kubelet, minikube       spec.containers{ls}     Normal      Pulling
        pulling image "tomcat"
  20s           15s             2       kubelet, minikube       spec.containers{ls}     Normal      Pulled
        Successfully pulled image "tomcat"
  20s           15s             2       kubelet, minikube       spec.containers{ls}     Normal      Created
        Created container
  20s           14s             2       kubelet, minikube       spec.containers{ls}     Normal      Started
        Started container
  14s           12s             3       kubelet, minikube       spec.containers{ls}     Warning     BackOff
        Back-off restarting failed container
  14s           12s             3       kubelet, minikube                               Warning     FailedSync
Error syncing pod

If using pwd with kubectl exec, command works fine.

-- user2491441
docker
kubernetes

2 Answers

9/3/2017

As described in the kubectl run documentation with --restart=Always (the default) a Deployment is created which is expected to run in the foreground and not exit - a daemon as @whites11 said that gets restarted. If you want the command to be run and then the container exit use --restart=Never which causes a Job to be created instead (see --generator) and that is expected in complete.

-- Keith Burdis
Source: StackOverflow

9/2/2017

The pwd command as you know is not a Daemon, it just executes and exits immediately. By default, kubernetes tries to restart any pod that exits. In your case, the pwd Command gets executed a few times, until k8s gives up because it failed too many times.

What are you trying to do exactly?

-- whites11
Source: StackOverflow