Setup Private K8s Repository Guide

There are multiple methods to set up a private Kubernetes repository, and here is one commonly used method:

  1. To install Docker, you first need to install it on the server to set up a private repository.
  2. Download and run a private repository image: Use Docker command to download a private repository image and create a running instance.
docker run -d -p 5000:5000 --restart=always --name registry registry:2

This command will create a private repository container named “registry” on the server, with port mapping set to 5000.

  1. Configuring Kubernetes to use a private repository: On each node in the Kubernetes cluster, modify the Docker configuration file so that it can access the private repository. Add the following content to the /etc/docker/daemon.json file:
{
  "insecure-registries": ["<私有仓库地址>:5000"]
}

The is the IP address or domain name of the server where the private repository is located.

  1. Restart the Docker service: Restart the Docker service on each node to apply the updated configuration.
sudo systemctl restart docker
  1. Build and push images: Use Docker commands to build images and push them to a private repository.
docker build -t <私有仓库地址>:5000/<镜像名称>:<标签> .
docker push <私有仓库地址>:5000/<镜像名称>:<标签>

Now, Kubernetes clusters can use images from a private repository.

bannerAds