Installing kubeadm

Installing kubeadm - 图1 This page shows how to install the kubeadm toolbox. For information on how to create a cluster with kubeadm once you have performed this installation process, see the Creating a cluster with kubeadm page.

Before you begin

  • A compatible Linux host. The Kubernetes project provides generic instructions for Linux distributions based on Debian and Red Hat, and those distributions without a package manager.
  • 2 GB or more of RAM per machine (any less will leave little room for your apps).
  • 2 CPUs or more.
  • Full network connectivity between all machines in the cluster (public or private network is fine).
  • Unique hostname, MAC address, and product_uuid for every node. See here for more details.
  • Certain ports are open on your machines. See here for more details.
  • Swap disabled. You MUST disable swap in order for the kubelet to work properly.
    • For example, sudo swapoff -a will disable swapping temporarily. To make this change persistent across reboots, make sure swap is disabled in config files like /etc/fstab, systemd.swap, depending how it was configured on your system.

Verify the MAC address and product_uuid are unique for every node

  • You can get the MAC address of the network interfaces using the command ip link or ifconfig -a
  • The product_uuid can be checked by using the command sudo cat /sys/class/dmi/id/product_uuid

It is very likely that hardware devices will have unique addresses, although some virtual machines may have identical values. Kubernetes uses these values to uniquely identify the nodes in the cluster. If these values are not unique to each node, the installation process may fail.

Check network adapters

If you have more than one network adapter, and your Kubernetes components are not reachable on the default route, we recommend you add IP route(s) so Kubernetes cluster addresses go via the appropriate adapter.

Check required ports

These required ports need to be open in order for Kubernetes components to communicate with each other. You can use tools like netcat to check if a port is open. For example:

  1. nc 127.0.0.1 6443

The pod network plugin you use may also require certain ports to be open. Since this differs with each pod network plugin, please see the documentation for the plugins about what port(s) those need.

Installing a container runtime

To run containers in Pods, Kubernetes uses a container runtime.

By default, Kubernetes uses the Container Runtime Interface (CRI) to interface with your chosen container runtime.

If you don’t specify a runtime, kubeadm automatically tries to detect an installed container runtime by scanning through a list of known endpoints.

If multiple or no container runtimes are detected kubeadm will throw an error and will request that you specify which one you want to use.

See container runtimes for more information.

Note: Docker Engine does not implement the CRI which is a requirement for a container runtime to work with Kubernetes. For that reason, an additional service cri-dockerd has to be installed. cri-dockerd is a project based on the legacy built-in Docker Engine support that was removed from the kubelet in version 1.24.

The tables below include the known endpoints for supported operating systems:

Linux container runtimes
RuntimePath to Unix domain socket
containerdunix:///var/run/containerd/containerd.sock
CRI-Ounix:///var/run/crio/crio.sock
Docker Engine (using cri-dockerd)unix:///var/run/cri-dockerd.sock
Windows container runtimes
RuntimePath to Windows named pipe
containerdnpipe:////./pipe/containerd-containerd
Docker Engine (using cri-dockerd)npipe:////./pipe/cri-dockerd

Installing kubeadm, kubelet and kubectl

You will install these packages on all of your machines:

  • kubeadm: the command to bootstrap the cluster.

  • kubelet: the component that runs on all of the machines in your cluster and does things like starting pods and containers.

  • kubectl: the command line util to talk to your cluster.

kubeadm will not install or manage kubelet or kubectl for you, so you will need to ensure they match the version of the Kubernetes control plane you want kubeadm to install for you. If you do not, there is a risk of a version skew occurring that can lead to unexpected, buggy behaviour. However, one minor version skew between the kubelet and the control plane is supported, but the kubelet version may never exceed the API server version. For example, the kubelet running 1.7.0 should be fully compatible with a 1.8.0 API server, but not vice versa.

For information about installing kubectl, see Install and set up kubectl.

Warning: These instructions exclude all Kubernetes packages from any system upgrades. This is because kubeadm and Kubernetes require special attention to upgrade.

For more information on version skews, see:

Note:

Kubernetes has two different package repositories starting from August 2023. The Google-hosted repository is deprecated and it’s being replaced with the Kubernetes (community-owned) package repositories. The Kubernetes project strongly recommends using the Kubernetes community-owned package repositories, because the project plans to stop publishing packages to the Google-hosted repository in the future.

There are some important considerations for the Kubernetes package repositories:

  • The Kubernetes package repositories contain packages beginning with those Kubernetes versions that were still under support when the community took over the package builds. This means that anything before v1.24.0 will only be available in the Google-hosted repository.
  • There’s a dedicated package repository for each Kubernetes minor version. When upgrading to to a different minor release, you must bear in mind that the package repository details also change.

  • Debian-based distributions

  • Red Hat-based distributions
  • Without a package manager

Kubernetes package repositories

These instructions are for Kubernetes 1.28.

  1. Update the apt package index and install packages needed to use the Kubernetes apt repository:

    1. sudo apt-get update
    2. # apt-transport-https may be a dummy package; if so, you can skip that package
    3. sudo apt-get install -y apt-transport-https ca-certificates curl
  2. Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:

    1. curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
  3. Add the appropriate Kubernetes apt repository:

    1. # This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
    2. echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
  4. Update the apt package index, install kubelet, kubeadm and kubectl, and pin their version:

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

Note: In releases older than Debian 12 and Ubuntu 22.04, /etc/apt/keyrings does not exist by default; you can create it by running sudo mkdir -m 755 /etc/apt/keyrings

Google-hosted package repository (deprecated)

These instructions are for Kubernetes 1.28.

  1. Update the apt package index and install packages needed to use the Kubernetes apt repository:

    1. sudo apt-get update
    2. # apt-transport-https may be a dummy package; if so, you can skip that package
    3. sudo apt-get install -y apt-transport-https ca-certificates curl
  2. Download the Google Cloud public signing key:

    1. curl -fsSL https://dl.k8s.io/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg
  3. Add the Google-hosted apt repository:

    1. # This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
    2. echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
  4. Update the apt package index, install kubelet, kubeadm and kubectl, and pin their version:

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

Note: In releases older than Debian 12 and Ubuntu 22.04, /etc/apt/keyrings does not exist by default; you can create it by running sudo mkdir -m 755 /etc/apt/keyrings

  1. Set SELinux to permissive mode:
  1. # Set SELinux in permissive mode (effectively disabling it)
  2. sudo setenforce 0
  3. sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

Caution:

  • Setting SELinux in permissive mode by running setenforce 0 and sed ... effectively disables it. This is required to allow containers to access the host filesystem; for example, some cluster network plugins require that. You have to do this until SELinux support is improved in the kubelet.
  • You can leave SELinux enabled if you know how to configure it but it may require settings that are not supported by kubeadm.

Kubernetes package repositories

These instructions are for Kubernetes 1.28.

  1. Add the Kubernetes yum repository. The exclude parameter in the repository definition ensures that the packages related to Kubernetes are not upgraded upon running yum update as there’s a special procedure that must be followed for upgrading Kubernetes.
  1. # This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
  2. cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
  3. [kubernetes]
  4. name=Kubernetes
  5. baseurl=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/
  6. enabled=1
  7. gpgcheck=1
  8. gpgkey=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key
  9. exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
  10. EOF
  1. Install kubelet, kubeadm and kubectl, and enable kubelet to ensure it’s automatically started on startup:
  1. sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
  2. sudo systemctl enable --now kubelet

Google-hosted package repository (deprecated)

These instructions are for Kubernetes 1.28.

  1. Add the Google-hosted yum repository. The exclude parameter in the repository definition ensures that the packages related to Kubernetes are not upgraded upon running yum update as there’s a special procedure that must be followed for upgrading Kubernetes.
  1. # This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
  2. cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
  3. [kubernetes]
  4. name=Kubernetes
  5. baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
  6. enabled=1
  7. gpgcheck=1
  8. gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
  9. exclude=kubelet kubeadm kubectl
  10. EOF
  1. Install kubelet, kubeadm and kubectl, and enable kubelet to ensure it’s automatically started on startup:
  1. sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
  2. sudo systemctl enable --now kubelet

Note: If the baseurl fails because your RPM-based distribution cannot interpret $basearch, replace \$basearch with your computer’s architecture. Type uname -m to see that value. For example, the baseurl URL for x86_64 could be: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64.

Install CNI plugins (required for most pod network):

  1. CNI_PLUGINS_VERSION="v1.3.0"
  2. ARCH="amd64"
  3. DEST="/opt/cni/bin"
  4. sudo mkdir -p "$DEST"
  5. curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/cni-plugins-linux-${ARCH}-${CNI_PLUGINS_VERSION}.tgz" | sudo tar -C "$DEST" -xz

Define the directory to download command files

Note: The DOWNLOAD_DIR variable must be set to a writable directory. If you are running Flatcar Container Linux, set DOWNLOAD_DIR="/opt/bin".

  1. DOWNLOAD_DIR="/usr/local/bin"
  2. sudo mkdir -p "$DOWNLOAD_DIR"

Install crictl (required for kubeadm / Kubelet Container Runtime Interface (CRI))

  1. CRICTL_VERSION="v1.28.0"
  2. ARCH="amd64"
  3. curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-${ARCH}.tar.gz" | sudo tar -C $DOWNLOAD_DIR -xz

Install kubeadm, kubelet, kubectl and add a kubelet systemd service:

  1. RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)"
  2. ARCH="amd64"
  3. cd $DOWNLOAD_DIR
  4. sudo curl -L --remote-name-all https://dl.k8s.io/release/${RELEASE}/bin/linux/${ARCH}/{kubeadm,kubelet}
  5. sudo chmod +x {kubeadm,kubelet}
  6. RELEASE_VERSION="v0.15.1"
  7. curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /etc/systemd/system/kubelet.service
  8. sudo mkdir -p /etc/systemd/system/kubelet.service.d
  9. curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

Install kubectl by following the instructions on Install Tools page.

Enable and start kubelet:

  1. systemctl enable --now kubelet

Note: The Flatcar Container Linux distribution mounts the /usr directory as a read-only filesystem. Before bootstrapping your cluster, you need to take additional steps to configure a writable directory. See the Kubeadm Troubleshooting guide to learn how to set up a writable directory.

The kubelet is now restarting every few seconds, as it waits in a crashloop for kubeadm to tell it what to do.

Configuring a cgroup driver

Both the container runtime and the kubelet have a property called “cgroup driver”, which is important for the management of cgroups on Linux machines.

Warning:

Matching the container runtime and kubelet cgroup drivers is required or otherwise the kubelet process will fail.

See Configuring a cgroup driver for more details.

Troubleshooting

If you are running into difficulties with kubeadm, please consult our troubleshooting docs.

What’s next