<p>I have a running kubernetes cluster for magento2. It has a pod for elasticsearch (you can see code <a href="https://github.com/KiweeEu/magento2-on-kubernetes/blob/2.3/deploy/bases/elasticsearch/elasticsearch.yaml" rel="nofollow noreferrer">here</a> ).</p>
<p>I need to change the image from elasticsearch:7.9.0 to a custom image.</p>
<p>Since using kustomize, I tried using a patch:</p>
<p>deploy/es-swap:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
  name: es_swap

bases:
  - ../step-4

patchesJson6902:
- path: patch/es.json
  target:
    group: elasticsearch.k8s.elastic.co
    version: v1
    kind: Elasticsearch
    name: elasticsearch
</code></pre>
<p>deploy/es-swap/es.json:</p>
<pre><code>[
    {
      &quot;op&quot;: &quot;replace&quot;,
      &quot;path&quot;: &quot;/spec/nodeSets/0/podTemplate/spec/containers/0/name&quot;,
      &quot;value&quot;: &quot;mydockerhubuser/elastic:v7.9.0_custom&quot;
    }
  ]
  
</code></pre>
<p>I deployed to patch like this:</p>
<pre><code>$ kustomize build deploy/es_swap | kubectl apply -f -
serviceaccount/ingress-nginx unchanged
serviceaccount/ingress-nginx-admission unchanged
:
elasticsearch.elasticsearch.k8s.elastic.co/elasticsearch configured
</code></pre>
<p>but it didn't actually work since it is still using previous image:</p>
<pre><code>$ k describe pod elasticsearch-es-elasticsearch-0 | grep image
  Normal   Pulled                  25m   kubelet                  Container image &quot;docker.elastic.co/elasticsearch/elasticsearch:7.9.0&quot; already present on machine
</code></pre>
<p>When checking output of <code>kustomize build deploy/es_swap</code> I see that <code>mydockerhubuser/elastic:v7.9.0_custom</code> is image of the elasticsearch container. So I don't understand why it is not swapped.</p>
<p>Another option that I was thinking about is that instead of changing the image, I can add initContainers, <a href="https://www.elastic.co/guide/en/cloud-on-k8s/1.0/k8s-init-containers-plugin-downloads.html" rel="nofollow noreferrer">as explained here</a>. I am not entirely sure how to do that.</p>
<p>I tried checking rollout and kubernetes patch, but I only see examples that apply them to deployments.</p>
<p>What is the way to change the image of this running pod?</p>

justadev
<p>kubernetes does not allow changing image in non-managed pods. that's just it.</p>
<p>if you need to rely on simple pods,you need to delete and recreate the resource with your changes.</p>
<p>however, you can create a deployment matching the current labels of your pod, which will make that pod managed by a deployment. then you are able to change the image in the deployment, leading to a pod with the updated image being created</p>
