<p>I have the following manifest that created the running pod named 'test'</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: hello-world
  labels:
    app: blue
spec:
  containers:
  - name: funskies
    image: busybox
    command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;echo 'Hello World'&quot;]
</code></pre>
<p>I want to update the pod to include the additional command</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: hello-world
  labels:
    app: blue
spec:
  containers:
  restartPolicy: Never
  - name: funskies
    image: busybox
    command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;echo 'Hello World' &gt; /home/my_user/logging.txt&quot;]
</code></pre>
<p><strong>What I tried</strong></p>
<pre><code>kubectl edit pod test
</code></pre>
<p><strong>What resulted</strong></p>
<pre><code># Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
# pods &quot;test&quot; was not valid:
# * spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`...
</code></pre>
<p><strong>Other things I tried:</strong></p>
<p><em>Updated the manifest and then ran apply - same issue</em></p>
<pre><code>kubectl apply -f test.yaml 
</code></pre>
<p><strong>Question:</strong> What is the proper way to update a running pod?</p>

<p>You can't modify most properties of a Pod.  Typically you don't want to directly create Pods; use a higher-level controller like a Deployment.</p>
<p>The <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podspec-v1-core" rel="nofollow noreferrer">Kubernetes documentation for a PodSpec</a> notes (emphasis mine):</p>
<blockquote>
<p><code>containers</code>: List of containers belonging to the pod. <strong>Containers cannot currently be added or removed.</strong> There must be at least one container in a Pod. <strong>Cannot be updated.</strong></p>
</blockquote>
<p>In all cases, no matter what, a container runs a single command, and if you want to change what that command is, you need to delete and recreate the container.  In Kubernetes this always means deleting and recreating the containing Pod.  Usually you shouldn't use bare Pods, but if you do, you can create a new Pod with the new command and delete the old one.  Deleting Pods is extremely routine and all kinds of ordinary things cause it to happen (updating Deployments, a HorizontalPodAutoscaler scaling down, ...).</p>
<p>If you have a Deployment instead of a bare Pod, you can freely change the <code>template:</code> for the Pods it creates.  This includes changing their <code>command:</code>.  This will result in the Deployment creating a new Pod with the new command, and once it's running, deleting the old Pod.</p>
<p>The sorts of very-short-lived single-command containers you show in the question aren't necessarily well-suited to running in Kubernetes.  If the Pod isn't going to stay running and serve requests, a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/" rel="nofollow noreferrer">Job</a> could be a better match; but a Job believes it will only be run once, and if you change the pod spec for a completed Job I don't think it will launch a new Pod.  You'd need to create a new Job for this case.</p>
