This post covers how the Kubernetes cluster in my homelab is deployed offline, and the pitfalls I ran into.
2025.06.02 update: tested
Offline deployment was one of the main scenarios I had in mind when designing the homelab; I wanted both offline installation and offline upgrades. The production network is isolated, so for many components, how to deploy them offline has to be worked out at selection time.
There are plenty of Kubernetes distributions; this one uses Kubespray. I’ll write about offline deployment for the others later.
Environment Preparation
11 nodes in total:
| name | role | desc |
|---|---|---|
| mirrors | N/A | Offline bundle build |
| nginx | Gateway | Offline bundle publishing |
| harbor | Image registry | Offline image registry |
| infra-master-1 | master | |
| infra-master-2 | master | |
| infra-master-3 | master | |
| infra-worker-1 | worker | |
| infra-worker-2 | worker | |
| infra-worker-3 | worker | |
| infra-worker-4 | worker | |
| infra-worker-5 | worker |
All nodes run Debian 12.
Environment Preparation
The 11 nodes are:
| name | role | desc |
|---|---|---|
| mirrors | N/A | Offline bundle build |
| nginx | Gateway | Offline bundle publishing |
| harbor | Image registry | Offline image registry |
| infra-master-1 | master | |
| infra-master-2 | master | |
| infra-master-3 | master | |
| infra-worker-1 | worker | |
| infra-worker-2 | worker | |
| infra-worker-3 | worker | |
| infra-worker-4 | worker | |
| infra-worker-5 | worker |
All nodes run Debian 12.
Node Configuration
Set up passwordless SSH on the nodes:
ssh-keygen
Copy the key to every node:
for ip in 10.31.0.{110..117}; do
ssh-copy-id user@$ip
done
Point apt at the internal mirror:
sed -i 's|http://|https://|g' /etc/apt/sources.list
sed -i 's|10.31.0.2|mirrors.infra.plz.ac|g' /etc/apt/sources.list
Building the Offline Bundle
💡 The steps below run on a node with internet access.
Install the dependencies:
sudo apt-get update
sudo apt-get install git wget ansible python3-venv -y
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
This is Docker’s official convenience script. Quick, but not meant for production; for production, set up the apt repository as described in the Docker docs.
Download the source:
git clone https://github.com/kubernetes-sigs/kubespray
Switch branches - pick whichever branch fits your needs:
cd kubespray
git switch release-2.28
Download the binaries:
cd contrib/offline
LC_ALL=C.UTF-8 bash generate_list.sh
wget -x -P temp/files -i temp/files.list
Keep this directory structure and put it on the NAS at 10.31.0.2. That box runs nginx to serve the files, though any web server you like will do.
scp -r temp/files/* [email protected]:/data/mirrors/k8s
Besides the binaries, the images have to be pulled as well, into either Harbor or a plain registry:
I wrote a script that copies all of them to the internal Harbor in bulk:
#!/bin/bash
# Proxy mapping
declare -A proxies=(
["docker.io"]="docker-proxy.plz.ac"
["ghcr.io"]="ghcr.plz.ac"
["registry.k8s.io"]="k8s-io.plz.ac"
["quay.io"]="quay.plz.ac"
)
# Read the image list file
input_file="$1"
harbor_registry="harbor.infra.plz.ac/k8s"
# Read the image list file
while IFS= read -r image; do
# Extract the registry and image name
registry=$(echo $image | cut -d '/' -f 1)
name=$(echo $image | cut -d '/' -f 2-)
# Pick the matching proxy
proxy=${proxies[$registry]}
if [ -z "$proxy" ]; then
echo "No proxy found for $registry"
continue
fi
# Build the proxied image URL
proxy_image="$proxy/$name"
# Pull the image
echo "Pulling image: $proxy_image"
docker pull $proxy_image
# Re-tag the image
echo "Tagging image: $proxy_image as $image"
docker tag $proxy_image $image
# Build the target image URL (drop the domain prefix; use library if there is no namespace)
if [[ $name == *"/"* ]]; then
target_image="$harbor_registry/$name"
else
target_image="$harbor_registry/library/$name"
fi
# Copy the image to Harbor with skopeo
echo "Copying image: $image to $target_image"
skopeo --insecure-policy copy docker-daemon:$image docker://$target_image
# Remove the intermediate images to save space
docker rmi $proxy_image
docker rmi $image
done < "$input_file"
Moving the images also uses skopeo:
wget -O skopeo https://github.com/lework/skopeo-binary/releases/download/v1.16.1/skopeo-linux-amd64
chmod +x skopeo
mv skopeo /usr/local/bin/skopeo
This is a third-party build. In production, verify the checksum or just use
skopeofrom your distribution’s repositories. Add the registry credentials:
skopeo login harbor.infra.plz.ac
Note that you have to create the Harbor projects by hand first, or the copies will fail.
The projects to create:
- mirantis
- coreos
- cilium
- k8snetworkplumbingwg
- flannel
- calico
- rajchaudhuri
- kubeovn
- cloudnativelabs
- kube-vip
- coredns
- dns
- cpa
- metrics-server
- sig-storage
- rancher
- ingress-nginx
- amazon
- jetstack
- kubernetesui
- metallb
Run it:
~/tools/images_pull.sh temp/images.list
During the deployment a few images still looked wrong, so I pushed them by hand:
docker pull registry.k8s.io/kube-apiserver:v1.32.5
docker tag registry.k8s.io/kube-apiserver:v1.32.5 harbor.infra.plz.ac/k8s/kube-apiserver:v1.32.5
docker push harbor.infra.plz.ac/k8s/kube-apiserver:v1.32.5
# The following images need the same treatment
kube-controller-manager:v1.32.5
kube-scheduler:v1.32.5
kube-proxy:v1.32.5
Deployment
Preparing the Config
Kubespray ships with a sample inventory. Copy it and adapt it to your environment:
cp -rv inventory/sample inventory/infra
Edit inventory/infra/group_vars/all/offline.yml as below. You need to change registry_host and files_repo; the tool URLs just need to be uncommented:
---
registry_host: "harbor.infra.plz.ac/k8s"
files_repo: "https://mirrors.infra.plz.ac/k8s"
kube_image_repo: "{{ registry_host }}"
gcr_image_repo: "{{ registry_host }}"
github_image_repo: "{{ registry_host }}"
docker_image_repo: "{{ registry_host }}"
quay_image_repo: "{{ registry_host }}"
kubeadm_download_url: "{{ files_repo }}/dl.k8s.io/release/v{{ kube_version }}/bin/linux/{{ image_arch }}/kubeadm"
kubectl_download_url: "{{ files_repo }}/dl.k8s.io/release/v{{ kube_version }}/bin/linux/{{ image_arch }}/kubectl"
kubelet_download_url: "{{ files_repo }}/dl.k8s.io/release/v{{ kube_version }}/bin/linux/{{ image_arch }}/kubelet"
cni_download_url: "{{ files_repo }}/github.com/containernetworking/plugins/releases/download/v{{ cni_version }}/cni-plugins-linux-{{ image_arch }}-v{{ cni_version }}.tgz"
crictl_download_url: "{{ files_repo }}/github.com/kubernetes-sigs/cri-tools/releases/download/v{{ crictl_version }}/crictl-v{{ crictl_version }}-{{ ansible_system | lower }}-{{ image_arch }}.tar.gz"
etcd_download_url: "{{ files_repo }}/github.com/etcd-io/etcd/releases/download/v{{ etcd_version }}/etcd-v{{ etcd_version }}-linux-{{ image_arch }}.tar.gz"
calicoctl_download_url: "{{ files_repo }}/github.com/projectcalico/calico/releases/download/v{{ calico_ctl_version }}/calicoctl-linux-{{ image_arch }}"
calico_crds_download_url: "{{ files_repo }}/github.com/projectcalico/calico/archive/v{{ calico_version }}.tar.gz"
ciliumcli_download_url: "{{ files_repo }}/github.com/cilium/cilium-cli/releases/download/v{{ cilium_cli_version }}/cilium-linux-{{ image_arch }}.tar.gz"
helm_download_url: "{{ files_repo }}/get.helm.sh/helm-v{{ helm_version }}-linux-{{ image_arch }}.tar.gz"
crun_download_url: "{{ files_repo }}/github.com/containers/crun/releases/download/{{ crun_version }}/crun-{{ crun_version }}-linux-{{ image_arch }}"
kata_containers_download_url: "{{ files_repo }}/github.com/kata-containers/kata-containers/releases/download/{{ kata_containers_version }}/kata-static-{{ kata_containers_version }}-{{ image_arch }}.tar.xz"
cri_dockerd_download_url: "{{ files_repo }}/github.com/Mirantis/cri-dockerd/releases/download/v{{ cri_dockerd_version }}/cri-dockerd-{{ cri_dockerd_version }}.{{ image_arch }}.tgz"
runc_download_url: "{{ files_repo }}/github.com/opencontainers/runc/releases/download/v{{ runc_version }}/runc.{{ image_arch }}"
crio_download_base: "download.opensuse.org/repositories/devel:kubic:libcontainers:stable"
crio_download_crio: "http://{{ crio_download_base }}:/cri-o:/"
crio_download_url: "{{ files_repo }}/storage.googleapis.com/cri-o/artifacts/cri-o.{{ image_arch }}.v{{ crio_version }}.tar.gz"
skopeo_download_url: "{{ files_repo }}/github.com/lework/skopeo-binary/releases/download/v{{ skopeo_version }}/skopeo-linux-{{ image_arch }}"
containerd_download_url: "{{ files_repo }}/github.com/containerd/containerd/releases/download/v{{ containerd_version }}/containerd-{{ containerd_version }}-linux-{{ image_arch }}.tar.gz"
nerdctl_download_url: "{{ files_repo }}/github.com/containerd/nerdctl/releases/download/v{{ nerdctl_version }}/nerdctl-{{ nerdctl_version }}-{{ ansible_system | lower }}-{{ image_arch }}.tar.gz"
gvisor_runsc_download_url: "{{ files_repo }}/storage.googleapis.com/gvisor/releases/release/{{ gvisor_version }}/{{ ansible_architecture }}/runsc"
gvisor_containerd_shim_runsc_download_url: "{{ files_repo }}/storage.googleapis.com/gvisor/releases/release/{{ gvisor_version }}/{{ ansible_architecture }}/containerd-shim-runsc-v1"
Deployment Prep
Create a virtual environment:
python3 -m venv ~/kubespray-basic-pyenv
Activate it:
. ~/kubespray-basic-pyenv/bin/activate
Point pip at a China mirror (there’s no internal sync mirror yet):
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Install the modules:
pip install -r requirements.txt
pip install ruamel.yaml
Set up the inventory:
vi inventory/infra/hosts.ini
It looks like this:
[all:vars]
# Global variables, applied to all hosts
ansible_user=user
# Assume local_release_dir is the releases directory under the remote user's home
# {{ ansible_user }} is replaced with the 'user' defined above
local_release_dir=/home/{{ ansible_user }}/releases
# To connect with an SSH key and point at a specific private key file, uncomment and edit the line below:
# ansible_ssh_private_key_file=<path-to-key> # replace with the real key path
[kube_control_plane]
# Kubernetes control plane nodes (masters)
# Format: <host alias> ansible_host=<ip> [other host variables]
infra-master-1 ansible_host=10.31.0.110
infra-master-2 ansible_host=10.31.0.111
infra-master-3 ansible_host=10.31.0.112
[etcd]
# etcd cluster nodes (usually the same as the control plane nodes)
infra-master-1 ansible_host=10.31.0.110
infra-master-2 ansible_host=10.31.0.111
infra-master-3 ansible_host=10.31.0.112
[kube_node]
# Worker nodes
infra-worker-1 ansible_host=10.31.0.113
infra-worker-2 ansible_host=10.31.0.114
infra-worker-3 ansible_host=10.31.0.115
infra-worker-4 ansible_host=10.31.0.116
infra-worker-5 ansible_host=10.31.0.117
Test connectivity:
ansible -i inventory/infra/hosts.ini -m ping all
Editing the extra add-ons
This is where you enable add-ons like a load balancer, Argo and Helm. Very convenient:
vi inventory/infra/group_vars/k8s_cluster/addons.yml
The contents:
---
dashboard_enabled: true
helm_enabled: false
registry_enabled: false
metrics_server_enabled: true
local_path_provisioner_enabled: false
local_volume_provisioner_enabled: false
ingress_nginx_enabled: true
ingress_publish_status_address: ""
ingress_alb_enabled: false
cert_manager_enabled: true
cert_manager_namespace: "cert-manager"
metallb_enabled: false
metallb_speaker_enabled: "{{ metallb_enabled }}"
metallb_namespace: "metallb-system"
argocd_enabled: false
kube_vip_enabled: false
node_feature_discovery_enabled: false
Editing the network plugin
There are many supported plugins; adjust inventory/infra/group_vars/k8s_cluster/k8s-cluster.yml as needed.
Parameters to change:
kube_proxy_mode: ipvs
kube_proxy_strict_arp: true
# These are the two I usually need; arp has to be on for the separate LB deployed later
cluster_name: infra.homelab # Set the cluster name explicitly
enable_nodelocaldns: false # Disabled nodelocaldns
auto_renew_certificates: true # Auto-renew cluster certificates
auto_renew_certificates_systemd_calendar: "Mon *-*-1,2,3,4,5,6,7 03:{{ groups['kube_control_plane'].index(inventory_hostname) }}0:00"
Deploy
Deploy:
ansible-playbook -i inventory/infra/hosts.ini --user=user --become --become-user=root cluster.yml
Adding Nodes
- Prepare the new node: SSH, time sync and the internal APT mirror.
- Add a line to
[kube_node]ininventory/infra/hosts.ini. - Run
scale.yml:
ansible-playbook -i inventory/infra/hosts.ini --user=user --become --become-user=root scale.yml
Uninstall
Reset the cluster:
ansible-playbook -i inventory/infra/hosts.ini --user=user --become --become-user=root reset.yml
Afterword
This setup has been running in the homelab for over a year now without problems. In a later homelab post I’ll cover serving traffic through an external LB and upgrading the cluster.
Troubleshooting
When a download fails, turn on debug logging for the download tasks:
ansible-playbook -i inventory/infra/hosts.ini -e "unsafe_show_logs=true" --user=user --become --become-user=root cluster.yml
Comments