2017-08-29 00:19:25 +03:00
# Bootstrapping the Kubernetes Worker Nodes
2025-04-07 04:32:30 +03:00
In this lab you will bootstrap two Kubernetes worker nodes. The following components will be installed: [runc ](https://github.com/opencontainers/runc ), [container networking plugins ](https://github.com/containernetworking/cni ), [containerd ](https://github.com/containerd/containerd ), [kubelet ](https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet ), and [kube-proxy ](https://kubernetes.io/docs/concepts/cluster-administration/proxies ).
2017-08-29 00:19:25 +03:00
## Prerequisites
2025-04-07 04:32:30 +03:00
The commands in this section must be run from the `jumpbox` .
Copy the Kubernetes binaries and systemd unit files to each worker instance:
2023-11-01 09:16:49 +03:00
```bash
2025-04-10 09:08:13 +03:00
for HOST in node-0 node-1; do
SUBNET=$(grep ${HOST} machines.txt | cut -d " " -f 4)
2023-11-01 09:16:49 +03:00
sed "s|SUBNET|$SUBNET|g" \
2025-04-07 04:32:30 +03:00
configs/10-bridge.conf > 10-bridge.conf
2023-11-01 09:16:49 +03:00
sed "s|SUBNET|$SUBNET|g" \
configs/kubelet-config.yaml > kubelet-config.yaml
2025-04-07 04:32:30 +03:00
2023-11-01 09:16:49 +03:00
scp 10-bridge.conf kubelet-config.yaml \
2025-04-10 09:08:13 +03:00
root@${HOST}:~/
2023-11-01 09:16:49 +03:00
done
```
```bash
2025-04-10 09:08:13 +03:00
for HOST in node-0 node-1; do
2023-11-01 09:16:49 +03:00
scp \
2025-04-10 09:08:13 +03:00
downloads/worker/* \
downloads/client/kubectl \
2023-11-01 09:16:49 +03:00
configs/99-loopback.conf \
configs/containerd-config.toml \
configs/kube-proxy-config.yaml \
units/containerd.service \
units/kubelet.service \
units/kube-proxy.service \
2025-04-10 09:08:13 +03:00
root@${HOST}:~/
done
```
```bash
for HOST in node-0 node-1; do
scp \
downloads/cni-plugins/* \
root@${HOST}:~/cni-plugins/
2023-11-01 09:16:49 +03:00
done
```
2025-04-07 04:32:30 +03:00
The commands in the next section must be run on each worker instance: `node-0` , `node-1` . Login to the worker instance using the `ssh` command. Example:
2023-11-01 09:16:49 +03:00
```bash
ssh root@node-0
2017-08-29 00:19:25 +03:00
```
## Provisioning a Kubernetes Worker Node
2017-10-02 06:37:09 +03:00
Install the OS dependencies:
2017-08-29 00:19:25 +03:00
2023-11-01 09:16:49 +03:00
```bash
2018-05-12 19:54:18 +03:00
{
2023-11-01 09:16:49 +03:00
apt-get update
2025-04-07 04:32:30 +03:00
apt-get -y install socat conntrack ipset kmod
2018-05-12 19:54:18 +03:00
}
2017-08-29 00:19:25 +03:00
```
2017-10-02 06:37:09 +03:00
> The socat binary enables support for the `kubectl port-forward` command.
2017-08-29 00:19:25 +03:00
2025-04-07 04:32:30 +03:00
Disable Swap
2019-09-14 21:41:56 +03:00
2025-04-07 04:32:30 +03:00
Kubernetes has limited support for the use of swap memory, as it is difficult to provide guarantees and account for pod memory utilization when swap is involved.
2019-09-14 21:41:56 +03:00
2025-04-07 04:32:30 +03:00
Verify if swap is disabled:
2019-09-14 21:41:56 +03:00
2023-11-01 09:16:49 +03:00
```bash
swapon --show
2019-09-14 21:41:56 +03:00
```
2025-04-07 04:32:30 +03:00
If output is empty then swap is disabled. If swap is enabled run the following command to disable swap immediately:
2019-09-14 21:41:56 +03:00
2023-11-01 09:16:49 +03:00
```bash
swapoff -a
2019-09-14 21:41:56 +03:00
```
> To ensure swap remains off after reboot consult your Linux distro documentation.
2017-08-29 00:19:25 +03:00
Create the installation directories:
2023-11-01 09:16:49 +03:00
```bash
mkdir -p \
2017-08-29 00:19:25 +03:00
/etc/cni/net.d \
/opt/cni/bin \
/var/lib/kubelet \
/var/lib/kube-proxy \
/var/lib/kubernetes \
/var/run/kubernetes
```
Install the worker binaries:
2023-11-01 09:16:49 +03:00
```bash
2018-05-12 19:54:18 +03:00
{
2025-04-10 09:08:13 +03:00
mv crictl kube-proxy kubelet runc \
/usr/local/bin/
mv containerd containerd-shim-runc-v2 containerd-stress /bin/
mv cni-plugins/* /opt/cni/bin/
2018-05-12 19:54:18 +03:00
}
2017-08-29 00:19:25 +03:00
```
### Configure CNI Networking
Create the `bridge` network configuration file:
2023-11-01 09:16:49 +03:00
```bash
mv 10-bridge.conf 99-loopback.conf /etc/cni/net.d/
2017-08-29 00:19:25 +03:00
```
2025-04-08 03:46:00 +03:00
To ensure network traffic crossing the CNI `bridge` network is processed by `iptables` , load and configure the `br-netfilter` kernel module:
```bash
{
modprobe br-netfilter
echo "br-netfilter" >> /etc/modules-load.d/modules.conf
}
```
```bash
{
echo "net.bridge.bridge-nf-call-iptables = 1" \
>> /etc/sysctl.d/kubernetes.conf
echo "net.bridge.bridge-nf-call-ip6tables = 1" \
>> /etc/sysctl.d/kubernetes.conf
sysctl -p /etc/sysctl.d/kubernetes.conf
}
```
2018-05-12 19:54:18 +03:00
### Configure containerd
2023-11-01 09:16:49 +03:00
Install the `containerd` configuration files:
2018-05-12 19:54:18 +03:00
2023-11-01 09:16:49 +03:00
```bash
2018-05-12 19:54:18 +03:00
{
2023-11-01 09:16:49 +03:00
mkdir -p /etc/containerd/
mv containerd-config.toml /etc/containerd/config.toml
mv containerd.service /etc/systemd/system/
2018-05-12 19:54:18 +03:00
}
```
2023-11-01 09:16:49 +03:00
### Configure the Kubelet
2018-09-30 22:35:05 +03:00
2023-11-01 09:16:49 +03:00
Create the `kubelet-config.yaml` configuration file:
2017-08-29 00:19:25 +03:00
2023-11-01 09:16:49 +03:00
```bash
{
mv kubelet-config.yaml /var/lib/kubelet/
mv kubelet.service /etc/systemd/system/
}
2017-08-29 00:19:25 +03:00
```
### Configure the Kubernetes Proxy
2023-11-01 09:16:49 +03:00
```bash
{
mv kube-proxy-config.yaml /var/lib/kube-proxy/
mv kube-proxy.service /etc/systemd/system/
}
2017-08-29 00:19:25 +03:00
```
### Start the Worker Services
2023-11-01 09:16:49 +03:00
```bash
2018-05-12 19:54:18 +03:00
{
2023-11-01 09:16:49 +03:00
systemctl daemon-reload
systemctl enable containerd kubelet kube-proxy
systemctl start containerd kubelet kube-proxy
2018-05-12 19:54:18 +03:00
}
2017-08-29 00:19:25 +03:00
```
2025-04-08 03:08:56 +03:00
Check if the kubelet service is running:
```bash
systemctl is-active kubelet
```
```text
active
```
2025-04-07 04:32:30 +03:00
Be sure to complete the steps in this section on each worker node, `node-0` and `node-1` , before moving on to the next section.
2017-08-29 00:19:25 +03:00
## Verification
2025-04-07 04:32:30 +03:00
Run the following commands from the `jumpbox` machine.
2017-08-29 00:19:25 +03:00
List the registered Kubernetes nodes:
2023-11-01 09:16:49 +03:00
```bash
ssh root@server \
"kubectl get nodes \
--kubeconfig admin.kubeconfig"
2017-08-29 00:19:25 +03:00
```
```
2023-11-01 09:16:49 +03:00
NAME STATUS ROLES AGE VERSION
2025-04-07 04:32:30 +03:00
node-0 Ready < none > 1m v1.32.3
node-1 Ready < none > 10s v1.32.3
2017-08-29 00:19:25 +03:00
```
Next: [Configuring kubectl for Remote Access ](10-configuring-kubectl.md )