The Problem:
I’m trying to install kubernetes to my offline environment with version 1.27.4. I have downloaded all the required packages and deployed a local registry to host the images. However, when I run the kubeadm init
command, it fails to pull the images from my local registry and instead tries to download them from the official registry. I’ve tried pushing both pause3.6
and pause3.9
images to my local registry, but kubeadm init
continues to fail. How can I prevent it from pulling images from the internet and force it to use the images in my local registry?
The Solutions:
Solution 1: Run Kubeadm init in online mode
kubeadm init
command requires internet connectivity to pull necessary docker images for setting up the Kubernetes cluster. In an offline environment, you can either temporarily connect to the internet to run the command and then go offline, or you can manually download the required docker images and deploy them before running kubeadm init
.
Solution 2: Deploy docker images manually
To deploy docker images manually, follow these steps:
- Download the required docker images from the official Kubernetes repository.
- Load the downloaded images into your local Docker registry.
- Edit the
kubeadm-config.yaml
file and replace the registry addresses with your local registry address. - Run
kubeadm init
with the updatedkubeadm-config.yaml
file.
Solution 3: Use kubeadm alpha offline image preloading
Kubeadm alpha now supports offline image preloading. To use this feature, follow these steps:
- Download the kubeadm alpha binary from the Kubernetes GitHub repository.
- Create a local registry and load the required docker images into it.
- Run
kubeadm alpha init phase prepull --registry-mirror=localhost:5000
to prepull the required images. - Run
kubeadm init
with the preloaded images.
Solution 2: Store Images Locally
Kubeadm typically pulls images from a remote registry. However, for offline environments, you can use a local docker image repository.
- Save Images as Tar Files: Save the necessary images as tar files.
- Copy Images Offline: Transfer the tar files to the offline machine.
- Load Images into Docker: Use
docker load
to load the tar files into Docker on the offline machine.
Now, when you run kubeadm init
, it will use the locally available images instead of pulling them remotely.
Q&A
How to handle the local image if local image version and required version (requested by kubeadm init) are different?
Update kubeadm configurations to use local image. Validate local image has the right tag and is accessible in the local registry.