Install Node Components #
Next, we’ll install the node components, focusing on kubelet
, the container runtime, and networking tools (commonly known as CNI plugins).
These steps should be performed on both node servers.
Most of the Node binaries will also be placed in /usr/local/bin
. You can add /usr/local/bin
to your PATH
in ~/.bash_profile
if you haven’t done so already.
# Same on both nodes
mkdir /usr/local/bin
echo "export PATH=$PATH:/usr/local/bin" >> ~/.bash_profile
source ~/.bash_profile
# Same on both nodes
mkdir /usr/local/bin
echo "export PATH=$PATH:/usr/local/bin" >> ~/.bash_profile
source ~/.bash_profile
Install Container Runtime #
On the Node, the primary interaction chain works as follows:
kubelet
directscontainerd
containerd
directsrunc
- Together,
containerd
andrunc
form the container runtime environment.
block-beta block a["kubelet"] b["containerd"] c["runc"] end
Our first step is to install containerd. Start by downloading the containerd package and extracting its contents to /usr/local/bin
.
# Same on both nodes
wget https://github.com/containerd/containerd/releases/download/v1.7.22/containerd-1.7.22-linux-amd64.tar.gz
tar Cxzvf /usr/local containerd-1.7.22-linux-amd64.tar.gz
# Same on both nodes
wget https://github.com/containerd/containerd/releases/download/v1.7.22/containerd-1.7.22-linux-amd64.tar.gz
tar Cxzvf /usr/local containerd-1.7.22-linux-amd64.tar.gz
Next, download the containerd.service
file, which has been provided by the official team.
# Same on both nodes
cd /etc/systemd/system/
wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
# Same on both nodes
cd /etc/systemd/system/
wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
Create the containerd configuration file at /etc/containerd/config.toml
.
# Same on both nodes
version = 2
[plugins."io.containerd.grpc.v1.cri"]
[plugins."io.containerd.grpc.v1.cri".containerd]
snapshotter = "overlayfs"
default_runtime_name = "runc"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
runtime_type = "io.containerd.runc.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
[plugins."io.containerd.grpc.v1.cri".cni]
bin_dir = "/opt/cni/bin"
conf_dir = "/etc/cni/net.d"
# Same on both nodes
version = 2
[plugins."io.containerd.grpc.v1.cri"]
[plugins."io.containerd.grpc.v1.cri".containerd]
snapshotter = "overlayfs"
default_runtime_name = "runc"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
runtime_type = "io.containerd.runc.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
[plugins."io.containerd.grpc.v1.cri".cni]
bin_dir = "/opt/cni/bin"
conf_dir = "/etc/cni/net.d"
Start containerd
and enable it to start on boot.
# Same on both nodes
systemctl daemon-reload
systemctl start containerd
systemctl enable containerd
# Same on both nodes
systemctl daemon-reload
systemctl start containerd
systemctl enable containerd
Next, download runc
and place it in /usr/local/bin
.
# Same on both nodes
cd /usr/local/bin
wget https://github.com/opencontainers/runc/releases/download/v1.1.14/runc.amd64
mv runc.amd64 runc
chmod +x runc
# Same on both nodes
cd /usr/local/bin
wget https://github.com/opencontainers/runc/releases/download/v1.1.14/runc.amd64
mv runc.amd64 runc
chmod +x runc
runc
doesn’t need to be started; just placing it here is sufficient.
Next, download the CNI plugins and place them in /opt/cni/bin
. Note that this path is different from those we used earlier; it’s a convention to place CNI plugins here.
Network configuration will be covered in a later section. For now, completing these steps is enough.
# Same on both nodes
mkdir -p /opt/cni/bin
wget https://github.com/containernetworking/plugins/releases/download/v1.5.1/cni-plugins-linux-amd64-v1.5.1.tgz
tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.5.1.tgz
# Same on both nodes
mkdir -p /opt/cni/bin
wget https://github.com/containernetworking/plugins/releases/download/v1.5.1/cni-plugins-linux-amd64-v1.5.1.tgz
tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.5.1.tgz
At this point, the container runtime installation is complete.
Install Kubelet #
Download kubelet
and place it in /usr/local/bin
。
# Same on both nodes
cd /usr/local/bin
wget https://dl.k8s.io/v1.31.1/bin/linux/amd64/kubelet
chmod +x kubelet
# Same on both nodes
cd /usr/local/bin
wget https://dl.k8s.io/v1.31.1/bin/linux/amd64/kubelet
chmod +x kubelet
Copy the kubeconfig
, CA certificate and key, as well as the client certificate and key from the Master node to the Node nodes.
Execute the following command on the master node.
# From master to Node01
scp /etc/kubernetes/admin.kubeconfig root@node01:/etc/kubernetes
scp /etc/kubernetes/pki/ca* root@node01:/etc/kubernetes/pki
scp /etc/kubernetes/pki/client* root@node01:/etc/kubernetes/pki
# From master to node02
scp /etc/kubernetes/admin.kubeconfig root@node02:/etc/kubernetes
scp /etc/kubernetes/pki/ca* root@node02:/etc/kubernetes/pki
scp /etc/kubernetes/pki/client* root@node02:/etc/kubernetes/pki
Create /etc/kubernetes/kubelet.yaml
and add the following content.
# Contents **NOT THE SAME** on the two nodes
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
anonymous:
enabled: false
webhook:
enabled: true
x509:
clientCAFile: "/etc/kubernetes/pki/ca.pem"
serverTLSBootstrap: true
port: 10250
clusterDomain: "cluster.local"
clusterDNS:
- "10.96.0.10"
authorization:
mode: Webhook
cgroupDriver: systemd
containerRuntimeEndpoint: "unix:///var/run/containerd/containerd.sock"
resolvConf: "/etc/resolv.conf"
runtimeRequestTimeout: "15m"
# On node01 it's 10.244.1.0/24,on node02 it's 10.244.2.0/24
podCIDR: "10.244.1.0/24"
# Contents **NOT THE SAME** on the two nodes
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
anonymous:
enabled: false
webhook:
enabled: true
x509:
clientCAFile: "/etc/kubernetes/pki/ca.pem"
serverTLSBootstrap: true
port: 10250
clusterDomain: "cluster.local"
clusterDNS:
- "10.96.0.10"
authorization:
mode: Webhook
cgroupDriver: systemd
containerRuntimeEndpoint: "unix:///var/run/containerd/containerd.sock"
resolvConf: "/etc/resolv.conf"
runtimeRequestTimeout: "15m"
# On node01 it's 10.244.1.0/24,on node02 it's 10.244.2.0/24
podCIDR: "10.244.2.0/24"
Prepare the SystemD service file for kubelet
at /etc/systemd/system/kubelet.service
. Be sure to set the --node-ip
parameter to the main IP of each Node. In this setup, these should be set to 192.168.56.11
and 192.168.56.12
respectively.
# Contents **NOT THE SAME** on the two nodes
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
[Service]
ExecStart=/usr/local/bin/kubelet --kubeconfig=/etc/kubernetes/admin.kubeconfig \
--node-ip=192.168.56.11 \
--config=/etc/kubernetes/kubelet.yaml \
--v=1
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
# Contents **NOT THE SAME** on the two nodes
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
[Service]
ExecStart=/usr/local/bin/kubelet --kubeconfig=/etc/kubernetes/admin.kubeconfig \
--node-ip=192.168.56.12 \
--config=/etc/kubernetes/kubelet.yaml \
--v=1
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Start kubelet
and enable it on start up.
# Same on both nodes
systemctl daemon-reload
systemctl start kubelet
systemctl enable kubelet
# Same on both nodes
systemctl daemon-reload
systemctl start kubelet
systemctl enable kubelet
At this point, the Node installation is complete.
Next, let’s Configure Network。