Recover container images from a running Kubernetes node
search cancel

Recover container images from a running Kubernetes node

book

Article ID: 437463

calendar_today

Updated On:

Products

VMware Tanzu Kubernetes Grid Management

Issue/Introduction

A user has deleted an image from Harbor

Environment

2.5.4

Resolution

The images can be rebuilt from a running K8s node:

  1. ssh into your nodes until you find one that has a copy of the image:
     
    # ssh <USER>@<K8SNODE>
     
  2. List the images on the node:
     
    # crictl images
    note the image name
     
  3. Export that image to a .tar file:
     
    # ctr -n k8s.io image export <OUTPUT-FILE> <IMAGE>:<TAG>
     
  4. Copy that output file to Harbor:
     
    # scp <OUTPUT-FILE> <USER>@<HARBOR>:/tmp
     
  5. Connect to Harbor via ssh:
     
    # ssh <USER>@<HARBOR>
     
  6. Change directory to where we copied the file:
     
    # cd /tmp
     
  7. Use Docker to rebuild the image from the exported layers from step 3:
     
    # docker load -i <OUTPUT-FILE>
     
  8. Push the image to Harbor:
     
    # docker push <IMAGE>:<TAG>
     
  9. Confirm in the Harbor UI that the image exists.
  10. Repeat for each image to be recovered.