Post

Kubernetes Control Plane Setup

Kubernetes Control Plane Setup

This guide has a pre-requirement from the Kubernetes Setup Guide. Please complete it before following this guide.

Getting Started

This document focuses on steps to setup the Control Plane only:

  • Install Kubernetes with deployment tools
  • Setup Kubernetes cluster
  • Install CNI: Calico
  • Print cluster join command

Install Kubernetes with Deployment Tools

Install Kubernetes v1.33. Start by adding the apt source:

1
2
3
4
5
6
7
8
9
# Add the Kubernetes repository
KUBERNETES_VERSION=v1.33
curl -fsSL https://pkgs.k8s.io/core:/stable:/$KUBERNETES_VERSION/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$KUBERNETES_VERSION/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list

# Add the CRI-O repository
CRIO_VERSION=v1.33
curl -fsSL https://download.opensuse.org/repositories/isv:/cri-o:/stable:/$CRIO_VERSION/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://download.opensuse.org/repositories/isv:/cri-o:/stable:/$CRIO_VERSION/deb/ /" | sudo tee /etc/apt/sources.list.d/cri-o.list

Update apt package index, install tools and pin their version:

1
2
3
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Setup Kubernetes Cluster

Before initializing the cluster, verify all nodes can communicate with each other. Then initialize the cluster (specifying pod-network-cidr and service-cidr to avoid conflicts):

1
sudo kubeadm init --apiserver-advertise-address=0.0.0.0 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/16

After completion, set up kubectl for your user:

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

Verify with:

1
kubectl get nodes

If the output shows the nodes list, everything is OK.

Install Network Plugin: Calico

Reference: Calico Quickstart

After initializing the cluster, coredns will be stuck in Pending state — you need to install the pod network add-on first.

Download the Calico manifest:

1
curl https://raw.githubusercontent.com/projectcalico/calico/v3.30.0/manifests/calico.yaml -O

If you changed the pod CIDR to 10.244.0.0/16 (not the default 192.168.0.0/16), update CALICO_IPV4POOL_CIDR before applying:

1
2
nano calico.yaml
# Update variable CALICO_IPV4POOL_CIDR to 10.244.0.0/16

Apply the manifest:

1
kubectl apply -f calico.yaml

Wait for coredns pods to reach Running state:

1
kubectl get pods -A

The system prints the join command after initialization. If you need it again later:

1
kubeadm token create --print-join-command

Use the output on worker nodes to join the cluster, then verify:

1
kubectl get nodes -o wide

New nodes take some time to start system pods; they will reach Ready state shortly.

Check all pods are running:

1
kubectl get pods -A

(Optional) Install via Shell Script

A bash script is available to automate the installation:

1
curl https://github.com/DevilDogTG/knowledge-base/raw/refs/heads/main/System%20Administrator/Kubernetes/scripts/setup-controlplane.sh | sudo bash
This post is licensed under CC BY 4.0 by the author.