Kubernetes: Configure Private Registry with Images

Earlier we saw how we can easily setup up docker private registry. Today lets see how we can populate it with images. For reference we are going to take RKE2 kubernetes cluster and set it up using our private registry.

Click here to see how to setup private registry.

Pre-Requisites

  • OS installed and updated
  • Reachability with Private Registry server
  • Containerd installed and service for containerd started and enabled
  • apparmor service installed, started and enabled
  • Private Registry Setup Successfully

Setup

Create a separate Directory for RKE2 Images

#mkdir rke2-1.24.9 && cd rke2-1.24.9

Fetch the image list from GitHub release page – For this document we will use the 1.24.9 version

#wget https://github.com/rancher/rke2/releases/download/v1.24.9%2Brke2r2/rke2-images.linux-amd64.txt

Check if the contents of the file is in proper format so we can directly pull

#for i in cat rke2-images.linux-amd64.txt; do echo $i; done

Pull the images

#for i in cat rke2-images.linux-amd64.txt; do docker pull $i; done

Once the images are pulled check with docker image command

#docker images

Tag the pulled images with the name of our private registry, for this we need the Image ID from the docker image command and then we need to add our details in the repository and append the existing tag with version

The Format would be:

#docker tag “image id” privreg.demolabs.com:443/”repository-name:existingtag”

Example:
#docker tag 6fb6fecc3b64 privreg.demolabs.com:443/rancher/rke2-runtime:v1.24.4-rke2r1

A small script that would do it for you is as below:

#docker images | grep "^rancher/"|awk '{print "docker tag " $3 " privreg.demolabs.com:443/" $1 ":" $2}' >> imagetotag.sh

#chmod +x imagetotag.sh && \#sh -x imagetotag.sh

Push the tagged images to your registry

#for i in docker images | grep privreg.demolabs.com:443 | awk {'print $1 ":" $2'}; do docker push $i; done

Additional Binaries like start stop script, kubectl and helm also would be needed so download them as well.

#mkdir binaries && cd binaries

#wget https://github.com/rancher/rke2/releases/download/v1.24.9%2Brke2r2/rke2.linux-amd64.tar.gz

#curl -LO [https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/

#kubectl](https://dl.k8s.io/release/$(curl -L -s https:/dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl)

#wget https://get.helm.sh/helm-v3.11.2-linux-amd64.tar.gz

Setup Helm in your private registry

#curl -fsSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 |bash

Conclusion

We saw how we can populate images in private registry. Next we will actually deploy a Kubernetes cluster using this private registry, so stay tuned.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!