kubernetes 1.27.4 init fails for offline environment – Kubernetes

by
Ali Hasan
alpine-linux boot2docker google-kubernetes-engine

Quick Fix: Either connect to the network to pull the docker image or manually download and deploy the kube-apiserver yaml file from K8s-the-hard-way repository.

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:

  1. Download the required docker images from the official Kubernetes repository.
  2. Load the downloaded images into your local Docker registry.
  3. Edit the kubeadm-config.yaml file and replace the registry addresses with your local registry address.
  4. Run kubeadm init with the updated kubeadm-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:

  1. Download the kubeadm alpha binary from the Kubernetes GitHub repository.
  2. Create a local registry and load the required docker images into it.
  3. Run kubeadm alpha init phase prepull --registry-mirror=localhost:5000 to prepull the required images.
  4. 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.

  1. Save Images as Tar Files: Save the necessary images as tar files.
  2. Copy Images Offline: Transfer the tar files to the offline machine.
  3. 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.