OS config, suggest by DeekThink
To deploy a k3s cluster on Alpine Linux VMs, follow these steps:
1. Prepare Alpine Linux VMs
- Setup VMs: Create Alpine Linux VMs (1 for the server, others as agents). Ensure they have:
- Minimum resources: 512MB RAM, 1 vCPU, 10GB disk (adjust based on workload).
- Network connectivity between nodes (ports
6443,8472/UDP for Flannel, and10250).
2. Configure cgroups on All Nodes
K3s requires cgroups for resource management. On each VM:
# Install necessary tools
apk add curl nano
# Enable cgroups
echo "default_kernel_opts=\"cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\"" >> /etc/update-extlinux.conf
# Update kernel and reboot
update-extlinux
reboot3. Install k3s Server
On the server node:
# Install k3s server (with Flannel on eth0)
curl -sfL https://get.k3s.io | sh -s - server --flannel-iface=eth0
# Enable and start service (if not already running)
rc-update add k3s default
service k3s start
# Verify node status
k3s kubectl get nodesRetrieve join token:
cat /var/lib/rancher/k3s/server/node-token4. Join Worker Nodes
On each agent node:
# Replace with your server IP and token
export K3S_URL="https://<SERVER_IP>:6443"
export K3S_TOKEN="<NODE_TOKEN>"
# Install k3s agent
curl -sfL https://get.k3s.io | sh -
# Enable and start agent service
rc-update add k3s-agent default
service k3s-agent start5. Verify Cluster
On the server node:
k3s kubectl get nodes6. Access Cluster Remotely
Copy the kubeconfig from the server:
cat /etc/rancher/k3s/k3s.yamlReplace 127.0.0.1 with the server’s IP in the copied k3s.yaml, then use it with kubectl.
Troubleshooting
- Logs: Check logs with
journalctl -u k3s(server) orjournalctl -u k3s-agent(workers). - Firewall: Ensure ports
6443(API),8472/UDP (Flannel), and10250(kubelet) are open. - cgroups: Verify cgroups are enabled post-reboot with
cat /proc/cmdline.
Optional: Use Specific Versions
Install a specific k3s version:
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.26.5+k3s1 sh -This setup provides a lightweight Kubernetes cluster using k3s on Alpine Linux. Adjust network interfaces (--flannel-iface) or CNI plugins as needed for your environment.