Initialise a Cluster

Initialize

To initialize a cluster the setup is quick and easy.

To initialize the cluster, run the following command on each control node to pull the control node containers

sudo kubeadm config images pull

Once the images have been pulled, run the following command on ONE control node to initialize the cluster.

Update --control-plane-endpoint to have the load balancer hostname or ip.

Update the pod network cidr if the range is already in use within your network.

sudo kubeadm init --control-plane-endpoint "hostname.domain:6443" --upload-certs --pod-network-cidr=10.244.0.0/16

Once initialized, note down the following at the end of the initialization output

You can now join any number of the control-plane node running the following command on each as root:

  kubeadm join hostname.domain:6443 --token token \
  --discovery-token-ca-cert-hash sha256:hash \
  --control-plane --certificate-key key

Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join hostname.domain:6443 --token token \
  --discovery-token-ca-cert-hash sha256:hash

Run the first command with sudo on each of the remaining control-plane nodes and run the second command on all the worker nodes.

Run the following commands on the control node

sudo kubeadm config images pull  # pull the control node container
sudo kubeadm init --upload-certs --pod-network-cidr=10.244.0.0/16  # Initialize the cluster

This will initialize the cluster for one control plane node and provide a join token to use when adding worker nodes. Run this command on each worker node, it will look like the following:

kubeadm join 192.168.1.27:6443 --token *token* \
  --discovery-token-ca-cert-hash sha256:*hash*

Configure kubectl

Run the following on your control node(s) to allow your user to use kubectl

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