简体   繁体   中英

Kubernetes pod is not starting

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.

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM