Benefit Kubernetes on your local Linux Ubuntu computer when on vacation
- ✅ Download and load all required dependencies easily
- ✅ Configure Kubernetes to use your own private registry
- ✅ Flannel and Ingress included
docker
on source (Internet)containerd
on target (air-gapped) hosts- A GitLab server or a container registry on target's network
-
Edit env variables to match target version for Kubernetes (default to 1.27.1)
cp .env.example .env
-
Retrieve images
docker-compose up --build download bash ./save-images.sh
-
Fully copy this repo with images present in
images/
and put it on your offline computer -
Setup an offline Kubernetes mirror
Download the
https://apt.kubernetes.io kubernetes-xenial main
mirror with apt-mirror-docker.Start apt-mirror-docker locally or on a remote server.
ℹ️ We recommend you to setup a full Ubuntu mirror on your offline infrastructure. You can use the default
mirror.list
file to download it.Append the following line to your
/etc/apt/sources.list
file :deb [arch=amd64] http://localhost:8080/apt.kubernetes.io kubernetes-xenial main
-
Install kubectl, kubectl and kubeadm
sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl sudo apt install -y kubelet=1.27.1-00 kubeadm=1.27.1-00 kubectl=1.27.1-00 containerd.io golang-docker-credential-helpers
-
Configure containerd with your private registry
Create a local repo in GitLab. Let's put it inside
mygroup/kubernetes
for the example !read -p "Enter your private registry URL (ex: gitlab.my.company): " private_registry read -p "Enter your GITLAB **username**: " username read -s -p "Enter your GITLAB **password**: " password cp ./containerd.config.example.toml ./containerd.config.toml docker_token=$(echo -n "$username:$password" | base64) sed -i "s/00000/$docker_token/g" ./containerd.config.toml sed -i "s/gitlab.my.company/$private_registry/g" ./containerd.config.toml # Change group and project if necessary sed -i "s/mygroup\/kubernetes/mygroup\/kubernetes/g" ./containerd.config.toml sudo mkdir -p /etc/containerd sudo cp ./containerd.config.toml /etc/containerd/config.toml sudo systemctl restart containerd
-
Load and push images to your local registry
Load images without pushing (dry-run) :
bash ./load-images.sh
Optionally push them :
bash ./load-images.sh -p
-
Install Kubernetes
sudo kubeadm config images pull \ --image-repository "$private_registry/mygroup/kubernetes" \ --cri-socket unix:///var/run/containerd/containerd.sock \ --kubernetes-version v1.27.1 sudo kubeadm init --config kubeadm-config.yml
-
Configure Kubernetes' CLI and private registry secrets
mkdir -p $HOME/.kube sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config kubectl create secret generic regcred --from-file=.dockerconfigjson=$HOME/.docker/config.json --type=kubernetes.io/dockerconfigjson kubectl create secret generic regcred --from-file=.dockerconfigjson=$HOME/.docker/config.json --type=kubernetes.io/dockerconfigjson -n kube-system
-
Configure the Flannel CNI
kubectl apply -f ./images/flannel.yaml
-
Configure Ingress
kubectl -n default apply -f ./images/ingress-nginx.yaml
-
Enjoy !
💼 No time to setup this kind of infrastructure ? Hire me 📬