Kubernetes Bare Metal
Jump to navigation
Jump to search
Cloud-Init YAML (
https://www.digitalocean.com/community/tutorials/bare-metal-kubernetes
You probably want to use cloud-init like this Ubuntu 24.04
cloud-init configuration for provisioning Kubernetes nodes on Ubuntu 24.04 LTS.
This script handles:
- Disabling swap (required by
kubelet) - Enabling necessary kernel modules (
overlay,br_netfilter) - Setting required
sysctlnetworking parameters - Installing and configuring
containerdwith theSystemdCgroupdriver enabled - Adding the official
pkgs.k8s.iorepository (configured for Kubernetes v1.30) - Installing and locking (
apt-mark hold)kubelet,kubeadm, andkubectl
Cloud-Init YAML (user-data)
#cloud-config
package_update: true
package_upgrade: false
packages:
- apt-transport-https
- ca-certificates
- curl
- gpg
- containerd
write_files:
# Enable required kernel modules for container networking
- path: /etc/modules-load.d/k8s.conf
permissions: '0644'
content: |
overlay
br_netfilter
# Set sysctl rules for iptables bridge & IP forwarding
- path: /etc/sysctl.d/k8s.conf
permissions: '0644'
content: |
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
runcmd:
# 1. Disable swap immediately and persistently across reboots
- swapoff -a
- sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# 2. Load kernel modules and apply sysctl settings
- modprobe overlay
- modprobe br_netfilter
- sysctl --system
# 3. Configure containerd with SystemdCgroup enabled
- mkdir -p /etc/containerd
- containerd config default | tee /etc/containerd/config.toml > /dev/null
- sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
- systemctl restart containerd
- systemctl enable containerd
# 4. Add official Kubernetes v1.30 apt repository
- mkdir -p -m 755 /etc/apt/keyrings
- curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
- chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg
- echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list
# 5. Install Kubernetes binaries and prevent auto-upgrades
- apt-get update
- apt-get install -y kubelet kubeadm kubectl
- apt-mark hold kubelet kubeadm kubectl
- systemctl enable --now kubelet
Next Steps After Boot
Once your machine finishes running cloud-init, choose your role:
For the Control Plane (Master Node)
Initialize the cluster with your control plane IP and preferred pod CIDR (e.g., Flannel/Calico):
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
For Worker Nodes
Run the kubeadm join command provided at the end of your control plane's kubeadm init output.