Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Know it before you install
A k3s server runs the control plane (and can run workloads too). Agents are worker nodes. Everything (containerd, flannel, CoreDNS, Traefik, ServiceLB, local-path storage, metrics-server) comes in the one k3s binary.
| Item | Value |
|---|---|
| Install | the script from get.k3s.io (binary in /usr/local/bin/k3s) |
| Services | k3s.service (server), k3s-agent.service (agent) |
| Config file | /etc/rancher/k3s/config.yaml |
| Kubeconfig | /etc/rancher/k3s/k3s.yaml |
| Join token | /var/lib/rancher/k3s/server/node-token |
| Data | /var/lib/rancher/k3s/ |
| Ports | 6443/tcp (API), 8472/udp (flannel VXLAN), 10250/tcp (kubelet), 2379–2380/tcp (embedded etcd, HA only) |
| Networks | Pods 10.42.0.0/16, Services 10.43.0.0/16 |
First configuration file (before the install)
Write the settings first — the install script reads them:
mkdir -p /etc/rancher/k3swrite-kubeconfig-mode: "0600"
tls-san:
- "k3s.example.com"
- "192.0.2.10"
node-name: "k3s-1"
secrets-encryption: true
disable:
- traefik| Setting | Why |
|---|---|
write-kubeconfig-mode: "0600" | Only root can read the admin kubeconfig. |
tls-san | The API certificate is valid for your DNS name and IP (for remote kubectl). |
secrets-encryption: true | Kubernetes Secrets are encrypted in the datastore. |
disable: [traefik] | Only when you want another ingress (for example ingress-nginx) or already run Nginx on 80/443. Leave Traefik on if you want it. |
Install the server on RHEL, Rocky and Alma
The script also installs the k3s-selinux policy on RHEL. Open the firewall for the k3s networks:
firewall-cmd --permanent --add-port=6443/tcp
firewall-cmd --permanent --add-port=10250/tcp
firewall-cmd --permanent --add-port=8472/udp
firewall-cmd --permanent --zone=trusted --add-source=10.42.0.0/16
firewall-cmd --permanent --zone=trusted --add-source=10.43.0.0/16
firewall-cmd --reload
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=stable sh -
systemctl status k3s --no-pager
k3s kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3s-1 Ready control-plane,master 40s v1.33.5+k3s1Install the server on Ubuntu and Debian
ufw allow 6443/tcp
ufw allow 10250/tcp
ufw allow 8472/udp
ufw allow from 10.42.0.0/16
ufw allow from 10.43.0.0/16
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=stable sh -
k3s kubectl get nodesOp het werk
Pin a version for production: INSTALL_K3S_VERSION=v1.33.5+k3s1. Read the script first if you like: curl -sfL https://get.k3s.io -o k3s-install.sh && less k3s-install.sh.
Add agents (worker nodes)
Read the token on the server, then run the script on each agent with the server address:
cat /var/lib/rancher/k3s/server/node-token
K10c1f…::server:9a7d…
curl -sfL https://get.k3s.io | K3S_URL=https://192.0.2.10:6443 K3S_TOKEN='K10c1f…::server:9a7d…' sh -
k3s kubectl get nodes -o wide(Open 10250/tcp and 8472/udp on agents too.) For a high-availability control plane, start the first server with cluster-init: true (embedded etcd) and join two more servers with server: https://first:6443 and the token.
Use kubectl from your laptop
Daily use: the commands and the real uses
k3s kubectl get nodes
k3s crictl ps
k3s crictl images
journalctl -u k3s -f
k3s check-config
kubectl get storageclass
kubectl get svc -n kube-systemBuilt-in parts you can use at once:
- local-path storage: a PVC gets a folder on the node (
/var/lib/rancher/k3s/storage). - ServiceLB: a
Service type: LoadBalancergets the node IPs — no cloud needed. - Traefik: an
Ingressworks on ports 80/443 (unless disabled). - Auto-deploy: YAML files in
/var/lib/rancher/k3s/server/manifests/are applied by themselves.
Real uses at work:
- Labs and CKA/CKS practice on one small VM.
- Small production clusters, branch offices, edge and IoT devices.
- CI test clusters that start in seconds.
Back up and upgrade
With embedded etcd (cluster-init), take snapshots (k3s also takes them every 12 hours by default):
With the default SQLite datastore, back up /var/lib/rancher/k3s/server/db/ and the token while k3s is stopped. Upgrade one minor version at a time by running the script again with the new version — servers first, then agents:
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.34.1+k3s1 sh -For many clusters use the system-upgrade-controller, which upgrades nodes from a Plan in the cluster.
Make it safe
Security checklist:
k3s.yamlandnode-tokenare master keys:600, never in Git, rotate if they leak.secrets-encryption: true; follow the k3s CIS hardening guide for production.- Firewall 6443 to admin networks only; agents and servers only talk to each other.
- Flannel enforces NetworkPolicies in k3s (kube-router policy controller is built in) — start with default-deny per namespace.
- Pin versions; upgrade at least every few months; back up before each upgrade.
Remove k3s
The install script also writes uninstall scripts:
/usr/local/bin/k3s-uninstall.sh
/usr/local/bin/k3s-agent-uninstall.shFix common problems
| Problem | Cause | Fix |
|---|---|---|
Agent stays NotReady or Pods can not talk across nodes | Firewall blocks 8472/udp or the Pod/Service networks. | Open the ports and trusted sources above; journalctl -u k3s-agent. |
Unable to connect to the server: x509: certificate is valid for 127.0.0.1, … | Your DNS name/IP is not in the certificate. | Add it to tls-san, restart k3s. |
permission denied reading k3s.yaml | Mode is 0600 (safe). | Use sudo, or copy it to ~/.kube/config with your owner. |
Traefik Pods Pending / ports 80/443 busy | Nginx or Apache already uses 80/443. | Stop the other server, or disable: [traefik]. |
Agent join fails: token error | Wrong token or server URL. | Copy the full node-token; use https://IP:6443. |
| Pods have no DNS | CoreDNS not running or firewall. | kubectl -n kube-system get pods; open the Pod network in the firewall. |
Next steps
- Command page: k3s, Command page: kubectl.
- k3s at work: A small real cluster, Clusters to practise.
- A full kubeadm cluster: Install a Kubernetes cluster with kubeadm. Apps on it: Install and set up Helm.
1Which file holds the admin login of a k3s cluster?
/etc/rancher/k3s/k3s.yaml.
2An agent joined but its Pods can not reach Pods on the server. What do you check first?
The firewall: 8472/udp (flannel VXLAN) and the Pod network 10.42.0.0/16.