DEV Community

Cover image for Kubernetes Installation with kubeadm
Daniel Puig Gerarde
Daniel Puig Gerarde

Posted on

Kubernetes Installation with kubeadm

Official Documentation

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.


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

  1. Update System Packages and install packages.

    sudo apt update
    sudo apt upgrade -y
    sudo apt install -y apt-transport-https ca-certificates curl
  2. Install Docker

    sudo apt install -y
    sudo usermod -aG docker $(whoami)

    Enable Docker to start at boot:

    sudo systemctl enable docker
  3. Disable Swap
    Kubernetes requires swap to be disabled. You can disable it on both nodes using

    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".

    sudo vi /etc/fstab
  4. Install Kubernetes
    Add the Kubernetes signing key:

    curl -s | sudo apt-key add -


    sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg

    Add the Kubernetes package source list:

    echo "deb kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list


    echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

    Update your package list and install Kubernetes tools:

    sudo apt update
    sudo apt install -y kubelet kubeadm kubectl
  5. 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=

    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:
    Then you can join any number of worker nodes by running the following on each as root:
    kubeadm join --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
  6. Installing a Pod network add-on

  • Install the Tigera Calico operator and custom resource definitions.
    kubectl create -f
Enter fullscreen mode Exit fullscreen mode
  • Confirm that all of the pods are running with the following command.
watch kubectl get pods -n calico-system
Enter fullscreen mode Exit fullscreen mode
  1. Join Worker Node to Cluster
    Execute the kubeadm join command that was output at the end of kubeadm 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

More Info

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:

  1. Plan: Use kubeadm upgrade plan to check which versions you can upgrade to.
  2. 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.

    kubectl drain <control-plane-node-name> --ignore-daemonsets
  3. Upgrade Control Plane: Upgrade the control plane (kube-apiserver, kube-controller-manager, kube-scheduler, and etcd):

    sudo kubeadm upgrade apply <new-version>
  4. Uncordon Master Node: Make the master node schedulable again.

    kubectl uncordon <control-plane-node-name>
  5. Upgrade Kubeadm on Worker Nodes: On each worker node, upgrade kubeadm to the latest version.

  6. Drain the Worker Nodes: Before upgrading worker nodes, they should be drained to minimize disruption to running applications.

  7. Upgrade the Worker Nodes: Upgrade the Kubernetes configuration on each worker node.

    sudo kubeadm upgrade node
  8. Uncordon the Worker Nodes: Once the upgrade is complete, make the worker node schedulable again.

  9. Upgrade kubectl on Each Node: After all nodes are upgraded, make sure to upgrade kubectl to the new version.

  10. Verify the Upgrade: Finally, verify that the upgrade was successful:

    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)