Initialize Kubernetes Control Plane with kubeadm
Kubernetes
Section titled “Kubernetes”Step 1: Install Kubernetes packages
Section titled “Step 1: Install Kubernetes packages”K8S_VERSION=$(grep -E "k8s_version:" ansible/group_vars/all.yaml | head -n 1 | awk -F'\"' '{print $2}')
sudo apt-get install -y apt-transport-https ca-certificates curl gpgsudo mkdir -p -m 755 /etc/apt/keyringscurl -fsSL https://pkgs.k8s.io/core:/stable:/$K8S_VERSION/deb/Release.key | \ sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$K8S_VERSION/deb/ /" | \ sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get updatesudo apt-get install -y kubelet kubeadm kubectlsudo apt-mark hold kubelet kubeadm kubectlStep 2: Initialize the control plane
Section titled “Step 2: Initialize the control plane”Pick a pod network CIDR that does not overlap your LAN or the service CIDR (default 10.96.0.0/12). For this homelab, 10.244.0.0/16 is fine. If you prefer Cilium to manage pod IPs without kubeadm pinning a range, omit --pod-network-cidr and keep the Cilium defaults.
sudo kubeadm init --pod-network-cidr=10.244.0.0/16mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configkubectl taint nodes --all node-role.kubernetes.io/control-plane-Optional: Enable Vault OIDC for Headlamp
Section titled “Optional: Enable Vault OIDC for Headlamp”If you want OIDC logins for Headlamp, add OIDC flags to the kubeadm config before the first kubeadm init. This avoids editing static manifests later.
Create clusters/home/kubeadm-clusterconfiguration.yaml with OIDC settings:
apiVersion: kubeadm.k8s.io/v1beta4kind: ClusterConfigurationapiServer: extraArgs: oidc-issuer-url: https://vault.sudhanva.me/v1/identity/oidc/provider/headlamp oidc-client-id: REPLACE_WITH_VAULT_CLIENT_ID oidc-username-claim: sub oidc-groups-claim: groups oidc-username-prefix: "oidc:" oidc-groups-prefix: "oidc:"Then initialize with:
sudo kubeadm init --config clusters/home/kubeadm-clusterconfiguration.yamlIf the cluster already exists, apply the same flags in /etc/kubernetes/manifests/kube-apiserver.yaml and let kubelet restart the API server.
Step 3: Join worker nodes
Section titled “Step 3: Join worker nodes”Follow Join Worker Nodes after the control plane is ready.
Step 4: Save kubeadm configuration
Section titled “Step 4: Save kubeadm configuration”mkdir -p clusters/homekubectl -n kube-system get configmap kubeadm-config -o jsonpath='{.data.ClusterConfiguration}' > clusters/home/kubeadm-clusterconfiguration.yaml