Home > Enterprise >  How to move a containerd image to different namespace?
How to move a containerd image to different namespace?

Time:11-28

I'm currently setting up a Kubernetes cluster with windows nodes. I accidentally created a local image in the default namespace.

As shown by ctr image ls, my image is in the default namespace:

REF                                 TYPE                                                   DIGEST       SIZE      PLATFORMS     LABELS
docker.io/library/myimage:latest   application/vnd.docker.distribution.manifest.v2 json   sha256:XXX   6.3 GiB   windows/amd64 -

Therefore, Kubernetes cannot find the image while creating the pod (ErrImageNeverPull, imagePullPolicy is set to Never). The reason for this is, the image isn't in the right namespace k8s.io:
The command ctr --namespace k8s.io image ls shows the base Kubernetes images:

REF                                                  TYPE                                                       DIGEST       SIZE       PLATFORMS                               LABELS
mcr.microsoft.com/oss/kubernetes/pause:3.6           application/vnd.docker.distribution.manifest.list.v2 json  sha256:XXX   3.9 KiB    linux/amd64,linux/arm64,windows/amd64   io.cri-containerd.image=managed
mcr.microsoft.com/oss/kubernetes/pause@sha256:DIGEST application/vnd.docker.distribution.manifest.list.v2 json  sha256:XXX   3.9 KiB    linux/amd64,linux/arm64,windows/amd64   io.cri-containerd.image=managed
...

The most straight-forward approach I tried, was exporting the image, deleting the image, and importing the image with different namespace. (as mentioned on a Github comment in the cri-tools project)

ctr --namespace k8s.io image import --base-name foo/myimage container_import.tar

It works. But I wonder, if there is any shorter (less time consuming) way than re-importing the image. (Maybe by running a simple command or changing a text file.)

CodePudding user response:

Consider podman save and load commands

CodePudding user response:

As @ P Ekambaram suggested, the podman save and podman load commands let you share images across multiple servers and systems when they aren't available locally or remotely.

You can use Podman to manage images and containers.

The podman save command saves an image to an archive, making it available to be loaded on another server.

For instance, to save a group of images on a host named servera:

[servera]$ podman save --output images.tar \
docker.io/library/redis \
docker.io/library/mysql \
registry.access.redhat.com/ubi8/ubi \
registry.access.redhat.com/ubi8/ubi:8.5-226.1645809065 \
quay.io/centos7/mysql-80-centos7 docker.io/library/nginx

Once complete, you can take the file images.tar to serverb and load it with podman load:

[serverb]$ podman load --input images.tar

The newly released Podman 4.0 includes the new podman image scp command, a useful command to help you manage and transfer container images.

With Podman's podman image scp, you can transfer images between local and remote machines without requiring an image registry.

Podman takes advantage of its SSH support to copy images between machines, and it also allows for local transfer. Registryless image transfer is useful in a couple of key scenarios:

Doing a local transfer between users on one system Sharing images over the network

  • Related