Install Kubernetes#
Before you begin#
- One or more machines running a deb/rpm-compatible Linux OS; for example: Ubuntu or CentOS.
- 2 GiB or more of RAM per machine--any less leaves little room for your apps.
- At least 2 CPUs on the machine that you use as a control-plane node.
- Full network connectivity among all machines in the cluster. You can use either a public or a private network.
General Setup For Control Planes and Node Machines#
Set Static IPs#
- using
ifconfig
to check the current IPv4. For example the current IPv4 is192.168.1.22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
- Then now, using the command below to edit file
50-cloud-init.yaml
1 |
|
- Update the content of this file as below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Key/Item | Description | Value |
---|---|---|
network | Top-level key defining the network configuration. | (N/A) |
ethernets | Specifies Ethernet interfaces for network configuration. | (N/A) |
enp0s3 | The name of the Ethernet interface being configured. | enp0s3 |
dhcp4 |
Indicates whether DHCP is used for IPv4. | false |
addresses |
Static IPv4 addresses assigned to the interface. | 192.168.1.22/24 |
nameservers |
DNS servers for domain name resolution. | 8.8.8.8 , 8.8.4.4 |
routes |
Defines custom routes for network traffic. | (N/A) |
to |
Specifies the destination for the route. default indicates all traffic. |
default |
via |
The gateway IP address for the route. | 192.168.1.1 |
version | Specifies the version of the Netplan YAML syntax being used. | 2 |
- Then run the command below to try and apply the latest configuration.
1 2 |
|
Turn Off Swap Permanently#
- Run commands below to turn off swap and make it turn off permanently after reboot.
1 2 3 4 5 |
|
Install Docker#
- Run commands below to install Docker.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
1 |
|
Setup Container Runtime#
- Run the command below:
1 2 3 |
|
- Then restart the
containerd
service and check the status.
1 2 3 |
|
Setup cgroup driver#
- Use the command below to open the
config.toml
.
1 |
|
- Then find the option
SystemCgroup
following part and set the value of it to true.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
- Then restart the
containerd
service and check the status.
1 2 3 |
|
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.
-
These instructions are for Kubernetes v1.32.
-
Update the
apt
package index and install packages needed to use the Kubernetesapt
repository:
1 2 3 |
|
- 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 2 3 |
|
- Add the appropriate Kubernetes
apt
repository. Please note that this repository have packages only for Kubernetes 1.32; for other Kubernetes minor versions, you need to change the Kubernetes minor version in the URL to match your desired minor version (you should also check that you are reading the documentation for the version of Kubernetes that you plan to install).
1 2 |
|
- Update the
apt
package index, installkubelet
,kubeadm
andkubectl
, and pin their version:
1 2 3 |
|
- Enable the kubelet service before running kubeadm:
1 |
|
Setup Control Plane#
Creating a cluster with kubeadm#
- Run commands below to check the network and make sure kubelet is enabled and pulls all the necessary container images for setting up the Kubernetes control plane.
1 2 3 |
|
Command | Explanation |
---|---|
lsmod \| grep br_netfilter |
Lists all the loaded kernel modules and filters the output to show the br_netfilter module. |
sudo systemctl enable kubelet |
Enables the kubelet service to start automatically on system boot. |
sudo kubeadm config images pull |
Pulls the required container images for setting up the Kubernetes control plane. |
- Then run the command below to init the control plane.
1 2 3 4 |
|
Command/Option | Explanation |
---|---|
kubeadm init |
Command to bootstrap a Kubernetes control plane node. This sets up all necessary components like the API server, controller manager, and scheduler. |
--pod-network-cidr=192.168.0.0/16 |
Specifies the CIDR block for the pod network. This is required to configure the networking for pods in the cluster. The value 192.168.0.0/16 is a common range for a pod network. It must match the network settings of the CNI plugin (like Flannel or Calico) you will install. |
--cri-socket unix:///run/containerd/containerd.sock |
Specifies the socket path to the container runtime interface (CRI). In this case, it points to the containerd socket. By default, Kubernetes may look for the docker socket, so this option ensures it uses containerd . |
--apiserver-advertise-address=192.168.12.13 |
Sets the IP address that the Kubernetes API server will advertise for communication with other nodes in the cluster. This should be the IP address of the control plane node. |