<p>I am trying <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#define-a-command-and-arguments-when-you-create-a-pod" rel="nofollow noreferrer">this</a> example from the Kubernetes docs to define a command to run when starting the container.</p>

<p>I've directly copied the .yaml in the given example which is like below:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: debian
    command: ["printenv"]
    args: ["HOSTNAME", "KUBERNETES_PORT"]
  restartPolicy: OnFailure
</code></pre>

<p>Then I've created the Pod with the <strong>kubectl apply -f command-demo.yaml</strong> </p>

<p>After that when I execute <strong>kubectl get pods</strong>, Pod is never starting:</p>

<pre><code>NAME                                 READY     STATUS             RESTARTS   AGE
command-demo                         0/1       Completed          0          2m
</code></pre>

<p>Also when I execute <strong>kubectl logs command-demo</strong> related environment variables gets printed. Ex:</p>

<pre><code>command-demo
tcp://10.80.2.3:443
</code></pre>

<p>It seems like when I use <strong>command</strong> in a yaml file, my pod is never starting but command is executed. Is there anyone got have any idea about this situation? Thanks in advance.</p>

Cemal Unal
<p>This is exactly the behavior described in the example. The pod starts and runs a command which finished directly and exits. When the command exits the pod is stopped. The lifecycle of a Pod depends on the process with the PID 1 which is the command defined in the yaml or in the used Docker file specified by <code>image</code>.</p>

<p>Because of the <code>restartPolicy: OnFailure</code> defined the pod will not be restarted and gets the Status Completed. If you remove the policy the default is Always and your pod will restart over and over again until you delete the pod manually.</p>

<p>You can check some more details with <code>kubectl descripe pod command-demo</code>.</p>

<p>Problem is the example is only for learning and did not represent a real life example. Normally you run commands which do not stop and should be running the whole time like web server. But these are normally managed by deployments. Or you run a command which should be executed once and finish but for these a Job is used.</p>

<p>So just follow the other tutorials from Kubernetes. In the <a href="https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/" rel="nofollow noreferrer">Run Applications</a> section will be an example with a webserver nginx which will start a pod and keeps running.</p>
