Build K3s Cluster
Install
Steps:
- Present
config.yamlfor the agent or server. - Run a convenient script for installing the k3s.
- Using
systemctlto manage the k3s service.
1. Config.yaml
Add config.yaml to /etc/rancher/k3s/config.yaml
Server config in server node
# node-name in k8s needing lowercase
node-name: host-01
# additional domain for certificate, it's necessary when you need to connect using domain
tls-san: "host-01.davidhsaiou.com"
# the network interface to bind (optional)
flannel-iface: wg0
# prepare certificate for further agent to join
cluster-init: true
# let the kubeconfig can read from none root user
write-kubeconfig-mode: 644
# allow unsafe sysctl config
# see kubelet conf
kubelet-arg:
- "allowed-unsafe-sysctls=net.ipv4.tcp_syn_retries,net.ipv4.ip_forward"
While inited, you can get the server token from
/var/lib/rancher/k3s/server/node-token
Agent config in agent node
# node name in k8s needing lowercase
node-name: pc-node-1
# the network interface to bind (optional)
flannel-iface: wg0
# server location with K8s apiserver port.
server: https://10.1.0.1:6443
# node label config (optional)
node-label:
- "gpu=true"
# node taint config (optional)
node-taint:
- "laptop=true:NoSchedule"
# the server token in /var/lib/rancher/k3s/server/node-token
token: <K3s server token>
# allow unsafe sysctl config
# see kubelet conf
kubelet-arg:
- "allowed-unsafe-sysctls=net.ipv4.tcp_syn_retries,net.ipv4.ip_forward"
2. Install Script
Server node
curl -sfL https://get.k3s.io | sh -s -
Agent node
curl -sfL https://get.k3s.io | sh -s - agent
3. Manage K3s using systemctl
Server Service name is
k3s
Agent Service name isk3s-agent
Checking Status
sudo systemctl status k3s
Stop k3s
sudo systemctl stop k3s
Restart k3s
sudo systemctl restart k3s