How to bind flannel to different iface

#k3s #kubernetes #cli

This is a short post on how to install k3s cluster with flannel binded to a different interface. This is useful when you have multiple network interfaces and you want to bind flannel to a specific one.

Master node install

  1. Change to root user
sudo -i
  1. Declare variables (it’s more readable than using the command directly)
export K3S_NODE_NAME=[node-name]
export K3S_EXTERNAL_IP=[node-ip]

# change kubeconfig permission
export K3S_KUBECONFIG_MODE=644

# install and specify desired interface
curl -sfL https://get.k3s.io | sh -s - --flannel-iface=[interface-name]

# check status
systemctl status k3s

# print kubernetes token
cat /var/lib/rancher/k3s/server/node-token
  1. Copy the token for the worker nodes

  2. Copy the kubeconfig

less /etc/rancher/k3s/k3s.yaml
  1. Exit root user
exit
  1. Create a folder called .kube in your home directory and create a file called kubeconfig inside it
mkdir -p $HOME/.kube

touch $HOME/.kube/kubeconfig
  1. Edit the file and paste the kubeconfig content

  2. Edit this line and enter correct ip address:

server: https://[master-ip]:6443

Worker node Install

  1. Change to root user
sudo -i
  1. Declare variables (it’s more readable than using the command directly)
export K3S_NODE_NAME=[node-name]
# change kubeconfig permission
export K3S_KUBECONFIG_MODE="644"
export K3S_EXTERNAL_IP=[node-ip]

export K3S_URL="https://[ip-of-master-node]:6443"
export K3S_TOKEN=[copied-token]

# install and specify desired interface
curl -sfL https://get.k3s.io | sh -s - --flannel-iface=[interface-name]

# check status
systemctl status k3s-agent

--flannel-iface=[interface-name] is the flag that binds flannel to the specified interface.