The kubeadm tool is good if you need:
- A simple way for you to try out Kubernetes, possibly for the first time.
- A way for existing users to automate setting up a cluster and test their application.
- A building block in other ecosystem and/or installer tools with a larger scope.
You can install and use kubeadm on various machines: your laptop, a set of cloud servers, a Raspberry Pi, and more. Whether you're deploying into the cloud or on-premises, you can integrate kubeadm into provisioning systems such as Ansible or Terraform.
Requirements
A Linux host that meets the following requirements:
- x86-64, arm64, ppc64le, or s390x processor
- 2CPU
- 2GB RAM
- 10GB free disk space
- RedHat Enterprise Linux 7.x+, CentOS 7.x+, Ubuntu 16.04+, or Debian 9.x+
Steps for Ubuntu 22.04 LTS
Root access or sudo privileges
- Update System Packages and install packages.
sh sudo apt update sudo apt upgrade -y sudo apt install -y apt-transport-https ca-certificates curl
- Install Docker
sh sudo apt install docker.io -y sudo usermod -aG docker $(whoami)
Enable Docker to start at boot:sh sudo systemctl enable docker
- Disable Swap
Kubernetes requires swap to be disabled. You can disable it on both nodes using
sh sudo swapoff -a
To make this change permanent, you have to edit the /etc/fstab file. Comment out the line that ends or include "swap".sh sudo vi /etc/fstab
- Install Kubernetes
Add the Kubernetes signing key:
sh curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
orsh sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
Add the Kubernetes package source list:sh echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
orsh echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
Update your package list and install Kubernetes tools:sh sudo apt update sudo apt install -y kubelet kubeadm kubectl
-
Configure Control Plane Node
sudo kubeadm init --pod-network-cidr=<server-ip>/16
Please be aware, --pod-network-cidr argument is usually used to specify the range of IP addresses for the pod network. For example, if you plan to use Calico as your network plugin, you would use --pod-network-cidr=192.168.0.0/16.
If you need to bind the API server to a specific IP address, you would typically use the --apiserver-advertise-address argument. So if you want to bind it to your server's IP, the command would be:
sudo kubeadm init --apiserver-advertise-address=<server-ip>
Sample Output:
Your Kubernetes control-plane has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config Alternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ Then you can join any number of worker nodes by running the following on each as root: kubeadm join 10.3.42.180:6443 --token i07joy.ml3fnm94v7c9amlm \ --discovery-token-ca-cert-hash sha256:c63c045c09ec9dbfc6184fd0adb1fa0fcd5f149b12585305cd84e78a85484369
The above command will output a kubeadm join command with a token. Keep note of the entire command; it's required to join the worker node to the cluster.
To make kubectl work for your non-root user, run these commands, which are also part of the kubeadm init output:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Installing a Pod network add-on
Calico:
- Install the Tigera Calico operator and custom resource definitions.
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/tigera-operator.yaml
- Confirm that all of the pods are running with the following command.
sh watch kubectl get pods -n calico-system
-
Join Worker Node to Cluster
Execute thekubeadm join
command that was output at the end ofkubeadm init
on the master node.sudo kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>
Replace , , , and with the respective values from the output of the kubeadm init command.
You can paste the section of the output generated in the step 5.Wait for a few minutes, then on the master node, check if the worker node has joined the cluster:
kubectl get nodes
You should see both the master and worker nodes listed.
That's it! You have now a functional Kubernetes cluster running
Manage the versions of the Cluster
Kubeadm is a powerful tool in Kubernetes that allows you to set up and upgrade a secure Kubernetes cluster easily. To upgrade a Kubernetes cluster using kubeadm, you'd typically follow these general steps:
-
Plan: Use
kubeadm upgrade
plan to check which versions you can upgrade to. -
Drain: Drain the control-plane node before upgrading it. This is done to ensure that the cluster remains available and no workloads will be interrupted during the upgrade.
sh kubectl drain <control-plane-node-name> --ignore-daemonsets
-
Upgrade Control Plane: Upgrade the control plane (kube-apiserver, kube-controller-manager, kube-scheduler, and etcd):
sh sudo kubeadm upgrade apply <new-version>
-
Uncordon Master Node: Make the master node schedulable again.
sh kubectl uncordon <control-plane-node-name>
- Upgrade Kubeadm on Worker Nodes: On each worker node, upgrade kubeadm to the latest version.
- Drain the Worker Nodes: Before upgrading worker nodes, they should be drained to minimize disruption to running applications.
-
Upgrade the Worker Nodes: Upgrade the Kubernetes configuration on each worker node.
sh sudo kubeadm upgrade node
- Uncordon the Worker Nodes: Once the upgrade is complete, make the worker node schedulable again.
- Upgrade kubectl on Each Node: After all nodes are upgraded, make sure to upgrade kubectl to the new version.
-
Verify the Upgrade: Finally, verify that the upgrade was successful:
sh kubectl get nodes
Remember, it is important to read the release notes for the version you're upgrading to before performing the upgrade, as there might be specific notes or issues related to that version.
I hope this step overview is helpful to you and your journey of learning more about Kubernetes.
Top comments (0)