'Is there an option to copy image between nodes in kubernetes cluster?

I have a case where we have to patch the docker image in k8s node and retag it to start over the old one. This process ain't so easy and obvious, because I have several nodes.

Therefore, could I do retag process only on one node and then copy a new image to other nodes? If there is a possibility to do so, then should I delete the old image before copying retagged one?



Solution 1:[1]

I advise you to clone your deployement and use your retaged image for your new nodes, and scale down the old deployement with the old image tag.

LP

Solution 2:[2]

It's not possible to do cluster to cluster copying. You'd need to use kubectl cp to copy it locally, then copy the file back:

kubectl cp :/tmp/test /tmp/test
kubectl cp /tmp/test :/tmp/test

If you are trying to share files bet,nx4ween pods, and only one pods needs write access, you probably want to mount an ro volume on multiple pods, or use an object store like S3. Copying files to and from pods really shouldn't be something you're doing often, that's an anti-pattern.

Solution 3:[3]

Best Practice:

could I do retag process only on one node and then copy a new image to other nodes?

Moreover you can create a private repo registry and push/pull your docker images from there.

So make change in your image, push to repo, now all nodes will able to pull the new image.

Ref: Setting Up a Private Docker Registry on Ubuntu 18.04

then should I delete the old image before copying retagged one

No, use image versioning.

Lets assume you are using image MyImage:1.1, now you make some changes and create new image with version 1.2, so your image will be MyImage:1.2

Now in your deployment file, change your image name to MyImage:1.2, and create the deployment. Now your deployment will upgraded with new image.

You can use Rolling Update for the upgrade strategy for zero downtime.

Moral :

In new IT world, we mostly work in multiple clusters with many nodes. We have regular changes or customization as per the client demand or business met. We cant just make change in single node and then pushing it to everyone 1-1, trust me it is very hectic.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lupaulus
Solution 2 Venkata Satya Karthik Varun Ku
Solution 3 dahiya_boy