Chapter 2. Creating a Kubernetes Cluster

In this chapter we discuss multiple ways to set up a full-blown Kubernetes cluster. We cover low-level, standardized tooling (kubeadm) that also serves as the basis for other installers and show you where to find the relevant binaries for the control plane, as well as for worker nodes. We demonstrate how to write systemd unit files to supervise Kubernetes components and finally show how to set up clusters on Google Cloud Platform and Azure.

2.1 Preparing a New Node for a Kubernetes Cluster

Problem

You want to prepare a new node with all the required tooling to create a new Kubernetes cluster or add to an existing cluster.

Solution

To prepare an Ubuntu-based host for a Kubernetes cluster, you first need to turn on IPv4 forwarding and enable iptables to see bridged traffic:

$ cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

$ sudo modprobe overlay
$ sudo modprobe br_netfilter

$ cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF

$ sudo sysctl --system

For compatibility with the kubeadm tool, the swap needs to be turned off on the node:

$ sudo apt install cron -y
$ sudo swapoff -a
$ (sudo crontab -l 2>/dev/null; echo "@reboot /sbin/swapoff -a") | sudo crontab -
|| true

Cluster nodes require an implementation of the Kubernetes Container Runtime Interface (CRI). cri-o is one such implementation. The cri-o version ...

Get Kubernetes Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.