Basic Network Options
This page describes K3s network configuration options, including configuration or replacement of Flannel, and configuring IPv6 or dualStack.
Flannel Options
Flannel is a lightweight provider of layer 3 network fabric that implements the Kubernetes Container Network Interface (CNI). It is what is commonly referred to as a CNI Plugin.
- Flannel options can only be set on server nodes, and must be identical on all servers in the cluster.
- The default backend for Flannel is
vxlan
. To enable encryption, use thewireguard-native
backend. - Using
vxlan
on Rasperry Pi with recent versions of Ubuntu requires additional preparation. - Using
wireguard-native
as the Flannel backend may require additional modules on some Linux distributions. Please see the WireGuard Install Guide for details. The WireGuard install steps will ensure the appropriate kernel modules are installed for your operating system. You must ensure that WireGuard kernel modules are available on every node, both servers and agents, before attempting to use the WireGuard Flannel backend.
CLI Flag and Value | Description |
---|---|
--flannel-ipv6-masq | Apply masquerading rules to IPv6 traffic (default for IPv4). Only applies on dual-stack or IPv6-only clusters. Compatible with any Flannel backend other than none . |
--flannel-external-ip | Use node external IP addresses as the destination for Flannel traffic, instead of internal IPs. Only applies when --node-external-ip is set on a node. |
--flannel-backend=vxlan | Use VXLAN to encapsulate the packets. May require additional kernel modules on Raspberry Pi. |
--flannel-backend=host-gw | Use IP routes to pod subnets via node IPs. Requires direct layer 2 connectivity between all nodes in the cluster. |
--flannel-backend=wireguard-native | Use WireGuard to encapsulate and encrypt network traffic. May require additional kernel modules. |
--flannel-backend=ipsec | Use strongSwan IPSec via the swanctl binary to encrypt network traffic. (Deprecated; will be removed in v1.27.0) |
--flannel-backend=none | Disable Flannel entirely. |
K3s no longer includes strongSwan swanctl
and charon
binaries starting with the 2022-12 releases (v1.26.0+k3s1, v1.25.5+k3s1, v1.24.9+k3s1, v1.23.15+k3s1). Please install the correct packages on your node before upgrading to or installing these releases if you want to use the ipsec
backend.
Migrating from wireguard
or ipsec
to wireguard-native
The legacy wireguard
backend requires installation of the wg
tool on the host. This backend is not available in K3s v1.26 and higher, in favor of wireguard-native
backend, which directly interfaces with the kernel.
The legacy ipsec
backend requires installation of the swanctl
and charon
binaries on the host. This backend is not available in K3s v1.27 and higher, in favor of the wireguard-native
backend.
We recommend that users migrate to the new backend as soon as possible. The migration requires a short period of downtime while nodes come up with the new configuration. You should follow these two steps:
- Update the K3s config on all server nodes. If using config files, the
/etc/rancher/k3s/config.yaml
should includeflannel-backend: wireguard-native
instead offlannel-backend: wireguard
orflannel-backend: ipsec
. If you are configuring K3s via CLI flags in the systemd unit, the equivalent flags should be changed. - Reboot all nodes, starting with the servers.
Custom CNI
Start K3s with --flannel-backend=none
and install your CNI of choice. Most CNI plugins come with their own network policy engine, so it is recommended to set --disable-network-policy
as well to avoid conflicts. Some important information to take into consideration:
- Canal
- Calico
- Cilium
Visit the Canal Docs website. Follow the steps to install Canal. Modify the Canal YAML so that IP forwarding is allowed in the container_settings
section, for example:
"container_settings": {
"allow_ip_forwarding": true
}
Apply the Canal YAML.
Ensure the settings were applied by running the following command on the host:
cat /etc/cni/net.d/10-canal.conflist
You should see that IP forwarding is set to true.
Follow the Calico CNI Plugins Guide. Modify the Calico YAML so that IP forwarding is allowed in the container_settings
section, for example:
"container_settings": {
"allow_ip_forwarding": true
}
Apply the Calico YAML.
Ensure the settings were applied by running the following command on the host:
cat /etc/cni/net.d/10-calico.conflist
You should see that IP forwarding is set to true.
Before running k3s-killall.sh
or k3s-uninstall.sh
, you must manually remove cilium_host
, cilium_net
and cilium_vxlan
interfaces. If you fail to do this, you may lose network connectivity to the host when K3s is stopped
ip link delete cilium_host
ip link delete cilium_net
ip link delete cilium_vxlan
Additionally, iptables rules for cilium should be removed:
iptables-save | grep -iv cilium | iptables-restore
ip6tables-save | grep -iv cilium | ip6tables-restore