Skip to content

Kubeadm init with Flannel

Step 2.2 — After Step 2.1 — Prepare the kubemaster node (Ansible has installed CRI-O, kubelet, and kubeadm packages), run kubeadm init on the control-plane VM and install Flannel as the pod network (CNI). Flannel’s default configuration expects the cluster pod CIDR 10.244.0.0/16, which you must pass to kubeadm init so the two match.

Run these commands on the kubemaster host (typically as root unless you have passwordless sudo for all steps).

Initialize the control plane

Use a --pod-network-cidr that matches Flannel ( 10.244.0.0/16 is the usual choice):

kubemaster
kubeadm init --pod-network-cidr=10.244.0.0/16

If the node has several network interfaces and the API server should listen on a specific address, set CONTROL_PLANE_IP and pass it in, for example:

kubemaster
export CONTROL_PLANE_IP=192.168.1.10
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=$CONTROL_PLANE_IP

Keep the kubeadm join ... line from the command output; you will need it for worker nodes (after Step 3.1 — Create kubeworker VMs and installing Kubernetes on those hosts).

Configure kubectl on the control plane

For root:

kubemaster
export KUBECONFIG=/etc/kubernetes/admin.conf

To use kubectl as a non-root user, copy the admin kubeconfig into your home directory:

kubemaster
mkdir -p "$HOME/.kube"
sudo cp -i /etc/kubernetes/admin.conf "$HOME/.kube/config"
sudo chown "$(id -u):$(id -g)" "$HOME/.kube/config"

Install Flannel

Apply the upstream Flannel manifest (check the Flannel documentation for the current URL if this fails):

kubemaster
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml

Wait until the control plane reports Ready and Flannel pods are running:

kubemaster
kubectl get nodes
kubectl get pods -n kube-flannel

What happens next

If you change the pod CIDR from 10.244.0.0/16, you must use a Flannel manifest (or configuration) that uses the same range; do not only change the kubeadm init flag.