we need 3 docker-compose file and .env file for each. note that first run node 1 compose and when its came up fully then run node2 and node3 to join first node.
Don't change network_mode: host and privileged: true to run K3S correctly.
there is another project name K3D but it doesn't support in separate Host in real HA .
All node .env file is same and I choose 192.168.50.10 for VRRP for control plain High Available IP and its run in separated HAProxy and Keepalived.
Add k3s.cluster.local to all nodes hosts file to make it resolvable.
K3S_TOKEN="QWERTYUIOPASDFGHJKLZXCVBNM"
THIS_NODE_IP=192.168.50.13
CONTROL_PLANE_ENDPOINT1=192.168.50.10
CONTROL_PLANE_ENDPOINT2=k3s.cluster.local
services:
k3s:
image: rancher/k3s:v1.35.1-k3s1
container_name: k3s-server1
restart: unless-stopped
privileged: true
network_mode: host
tmpfs:
- /run
- /var/run
volumes:
- k3s-data:/var/lib/rancher/k3s
- /var/run/docker.sock:/var/run/docker.sock
environment:
- K3S_TOKEN=${K3S_TOKEN}
command: >
server
--cluster-init
--token ${K3S_TOKEN}
--node-ip ${THIS_NODE_IP}
--advertise-address ${THIS_NODE_IP}
--tls-san ${CONTROL_PLANE_ENDPOINT1}
--tls-san ${CONTROL_PLANE_ENDPOINT2}
--disable=servicelb,traefik,metrics-server
--flannel-iface=enp1s0
--disable-network-policy
volumes:
k3s-data:
services:
k3s:
image: rancher/k3s:v1.35.1-k3s1
container_name: k3s-server2
restart: unless-stopped
privileged: true
network_mode: host
tmpfs:
- /run
- /var/run
volumes:
- k3s-data:/var/lib/rancher/k3s
- /var/run/docker.sock:/var/run/docker.sock
environment:
- K3S_TOKEN=${K3S_TOKEN}
command: >
server
--server https://${CONTROL_PLANE_ENDPOINT2}:6443
--token ${K3S_TOKEN}
--node-ip ${THIS_NODE_IP}
--advertise-address ${THIS_NODE_IP}
--tls-san ${CONTROL_PLANE_ENDPOINT1}
--tls-san ${CONTROL_PLANE_ENDPOINT2}
--disable=servicelb,traefik,metrics-server
--flannel-iface=enp1s0
--disable-network-policy
volumes:
k3s-data:
services:
k3s:
image: rancher/k3s:v1.35.1-k3s1
container_name: k3s-server3
restart: unless-stopped
privileged: true
network_mode: host
tmpfs:
- /run
- /var/run
volumes:
- k3s-data:/var/lib/rancher/k3s
- /var/run/docker.sock:/var/run/docker.sock
environment:
- K3S_TOKEN=${K3S_TOKEN}
command: >
server
--server https://${CONTROL_PLANE_ENDPOINT2}:6443
--token ${K3S_TOKEN}
--node-ip ${THIS_NODE_IP}
--advertise-address ${THIS_NODE_IP}
--tls-san ${CONTROL_PLANE_ENDPOINT1}
--tls-san ${CONTROL_PLANE_ENDPOINT2}
--disable=servicelb,traefik,metrics-server
--flannel-iface=enp1s0
--disable-network-policy
volumes:
k3s-data: