<p>I want to restart deployment pod by patching ENV variable in deployment. Here is my code:</p>
<pre><code>String PATCH_STR =  &quot;[{\&quot;op\&quot;:\&quot;replace\&quot;,\&quot;path\&quot;:\&quot;/spec/template/spec/containers/0/env/8/UPDATEDON\&quot;,\&quot;value\&quot;: \&quot;%d\&quot;}]&quot;;

final String patchStr = String.format(PATCH_STR, System.currentTimeMillis());

                AppsV1Api api = new AppsV1Api(apiClient);
                V1Deployment deploy = PatchUtils.patch(V1Deployment.class,
                    () -&gt; api.patchNamespacedDeploymentCall(
                            deploymentName,
                            namespace,
                            new V1Patch(patchStr),
                            null,
                            null,
                            null, // field-manager is optional
                            null,
                            null),
                    V1Patch.PATCH_FORMAT_JSON_PATCH,
                    apiClient);
</code></pre>
<p>This code executes successfully but it does not start pod. Here is an equivalent kubectl command (it doesn't patch, so pod doesn't start):</p>
<pre><code>kubectl -n aaaac7bg7b6nsaaaaaaaaaaoyu patch deployment aaaaaaaaxldpcswy2bl3jee6umwck72onc55wimyvldrfc442rokz3cpll2q -p '{&quot;spec&quot;:{&quot;containers&quot;:[{&quot;env&quot;:[{&quot;name&quot;:&quot;UPDATEDON&quot;,&quot;value&quot;:&quot;1645099482000&quot;}]}]}}'
</code></pre>
<p>If I execute following command, it restarts pod:</p>
<pre><code>kubectl -n aaaac7bg7b6nsaaaaaaaaaaoyu set env deployment/aaaaaaaaxldpcswy2bl3jee6umwck72onc55wimyvldrfc442rokz3cpll2q UPDATEDON=1645099482000
</code></pre>
<p>I thought of using <code>V1EnvVar/V1EnvVarBuilder</code> but I couldn't find equivalent java code.</p>

Pushpendra
<p>There are a couple of issues with your example. In general, if you <em>successfully update</em> the environment variables in the pod template of your deployment, the Kubernetes operator will recognize the change and start a new pod to reflect the change.</p>
<p>When you perform the update with a JSON patch by specifying the operation (<code>replace</code>), the path, and the value, the path must directly match the property in the deployment manifest. In your case, since you want to change the <code>value</code> of the environment variable, this would be:</p>
<pre><code>/spec/template/spec/containers/0/env/8/value
</code></pre>
<p>There is no need to repeat the name of the environment variable. The index, here <code>8</code>, already signifies which variable you want to update, so there is no need to repeat <code>UPDATEDON</code>.</p>
<p>The equivalent command with <code>kubectl</code> would be</p>
<pre><code>kubectl -n aaaac7bg7b6nsaaaaaaaaaaoyu patch deployment aaaaaaaaxldpcswy2bl3jee6umwck72onc55wimyvldrfc442rokz3cpll2q \
--type=json -p='[{&quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/template/spec/containers/0/env/0/value&quot;, &quot;value&quot;: &quot;1645099482000&quot;}]'
</code></pre>
<p>Alternatively, instead of using a JSON patch, you can used the default patch type, like you did in your example. However, you forgot to add the outermost <code>spec/template</code> layers. Addionaly, you also need the given identify the container by specifying it's name. Here I've used <code>test</code> as the container's name.</p>
<pre><code>kubectl -n aaaac7bg7b6nsaaaaaaaaaaoyu patch deployment aaaaaaaaxldpcswy2bl3jee6umwck72onc55wimyvldrfc442rokz3cpll2q \
-p '{&quot;spec&quot;: {&quot;template&quot;: {&quot;spec&quot;: {&quot;containers&quot;: [{&quot;name&quot;: &quot;test&quot;, &quot;env&quot;:[{&quot;name&quot;:&quot;UPDATEDON&quot;,&quot;value&quot;:&quot;1645099482000&quot;}]}]}}}}'
</code></pre>
<p>This way of updating has the advantage that you identify the container and the environment variable by their names, so and you don't need to rely on the ordering as would be the case with the index-based JSON patch path.</p>
