我要评分
获取效率
正确性
完整性
易理解

Installing and Configuring Kubernetes Nodes

Install and configure Kubernetes on the management and compute nodes in the cluster.

Changing the Host Name and Mapping

Perform the operations on all management and compute nodes.

  1. Set the host name of each node.

    Management node:

    hostnamectl set-hostname master

    Compute node 1:

    hostnamectl set-hostname compute01

    Compute node 2:

    hostnamectl set-hostname compute02

    After the setting is complete, log in to the OS again for the change to take effect.

  2. Modify the hosts files on all nodes.
    1. Open the hosts file.
      vi /etc/hosts
    2. Press i to enter the insert mode and add the IP addresses and host names of all nodes in the cluster to the configuration file.
      192.168.1.11 master
      192.168.1.12 compute01
      192.168.1.13 compute02

      See the result:

    3. Press Esc, type :wq!, and press Enter to save the file and exit.

Installing the Base Components

  1. Disable the firewall.
    systemctl stop firewalld && systemctl disable firewalld
  2. Install Docker.
    yum install -y docker
    cat <<EOF > /etc/docker/daemon.json
    {
            "exec-opts": ["native.cgroupdriver=systemd"]
    }
    EOF
    systemctl daemon-reload
    systemctl restart docker
  3. Enable the NET.BRIDGE.BRIDGE-NF-CALL-IPTABLES kernel option.
    sysctl -w net.bridge.bridge-nf-call-iptables=1
  4. Disable the swap partition.
    1. Disable the swap partition.
      swapoff -a
    1. Open the /etc/fstab file.
      vi /etc/fstab
    2. Press i to enter the insert mode and comment out the swap partition information.
      # /dev/mapper/openeuler-swap none                    swap    defaults        0 0
    3. Press Esc to exit the insert mode. Type :wq! and press Enter to save the file and exit.
  5. Install Kubernetes.
    yum install -y kubelet kubeadm kubectl kubernetes-cni

    If the above command fails to be executed, run the following command:

    yum install -y kubelet kubeadm kubectl kubernetes-cni --nobest
  6. Check the Kubernetes installation status.
    rpm -qa | grep kubelet 
    rpm -qa | grep kubeadm 
    rpm -qa | grep kubectl 
    rpm -qa | grep kubernetes-cni
  7. Configure iptables.
    echo "net.bridge.bridge-nf-call-iptables=1" > /etc/sysctl.d/k8s.conf
  8. Enable the kubelet service.
    systemctl enable kubelet

Configuring NTP

Configure NTP to synchronize the time between nodes in the cluster.

  1. Install chrony and set the time zone on all nodes. In this document, an Asian time zone is used as an example.
    yum install -y chrony
    timedatectl set-timezone Asia/Shanghai
  2. Set the management node as the NTP server node.
    1. Open the /etc/chrony.conf file.
      vi /etc/chrony.conf
    2. Press i to enter the insert mode and add the following content:
      allow 192.168.1.0/24
      local stratum 10

      Replace the example network segment 192.168.1.0/24 with the actual one.

    1. Press Esc to exit the insert mode. Type :wq! and press Enter to save the file and exit.
  3. Configure compute nodes as NTP clients.
    1. Open the /etc/chrony.conf file.
      vi /etc/chrony.conf
    2. Press i to enter the insert mode and comment out the following line:
      pool pool.ntp.org iburst

      The following figure shows the modification result:

      Add the following content:

      server master iburst
    3. Press Esc to exit the insert mode. Type :wq! and press Enter to save the file and exit.
  4. Start the NTP service.
    1. Start the NTP service on all nodes and check the service status.
      systemctl enable chronyd.service 
      systemctl start chronyd.service 
      systemctl status chronyd.service
    2. Start NTP synchronization on all nodes.
      timedatectl set-ntp no
      timedatectl set-ntp yes
  5. Verify time synchronization.
    chronyc sources

    The clock source on the compute node is master:

    Run the date command on each node to check whether the time is the same.

    date

Downloading Other Components Using Docker

Perform the following steps on all nodes in the cluster.

  1. View the image list and determine the Docker image version to be downloaded.
    kubeadm config images list
    • Different versions of Kubernetes may require different versions of Docker images. Therefore, you need to view the image list and select the right Docker image version. The Docker image version used in 2 is for reference only.
    • Ensure that the downloaded Docker image supports the Arm architecture.
  2. Download the image from Docker Hub.
    • If openEuler 22.03 is used, you are advised to install Kubernetes 1.23.1.
      docker pull k8s.gcr.io/kube-apiserver:v1.23.1 
      docker pull k8s.gcr.io/kube-controller-manager:v1.23.1 
      docker pull k8s.gcr.io/kube-scheduler:v1.23.1 
      docker pull k8s.gcr.io/kube-proxy:v1.23.1 
      docker pull k8s.gcr.io/pause:3.6 
      docker pull k8s.gcr.io/etcd:3.5.1-0 
      docker pull k8s.gcr.io/coredns/coredns:v1.8.6
    • If openEuler 20.03 or CentOS is used, you are advised to install Kubernetes 1.18.20.
      1
      2
      3
      4
      5
      6
      7
      docker pull k8smx/kube-apiserver:v1.18.20
      docker pull k8smx/kube-controller-manager:v1.18.20
      docker pull k8smx/kube-scheduler:v1.18.20
      docker pull k8smx/kube-proxy:v1.18.20
      docker pull k8smx/pause:3.2
      docker pull k8smx/coredns:1.6.7
      docker pull k8smx/etcd:3.4.3-0
      

    If you cannot pull images from dockerhub.io, you are advised to configure the Docker image accelerator in advance and use other image sources to download the required Docker images. For details about how to change the image source, see Changing the Image Source.

  3. Query the Docker image components of Kubernetes.
    docker images | grep k8s