Rancher installation and creation of K8S cluster

Preparation

System requirements: Ubuntu1804/Ubuntu Server 1804

Number of servers: number of servers in cluster mode ≥ 2, number of servers in single node mode = 1

replace domestic sources

Backup source list file:

sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

To replace the source, first VIM opens /etc/apt/sources.list:

sudo vim /etc/apt/sources.list

Enter a new source, and save:

#  阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

refresh cache:

sudo apt update

Install Docker

The installation command is as follows:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

You can also use the domestic daocloud one-click installation command:

curl -sSL https://get.daocloud.io/docker | sh

Check if the installation was successful:

docker --version

Note that docker needs to be installed on each server node.

Replace the Docker domestic source

Replace Alibaba's domestic source to increase the speed of image pull:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://sx1pmhon.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Static IP

Configuring static ip here requires flexible configuration of the number of server network cards. Each node needs to be executed.

  • Backup NIC configuration:
sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak
  • Edit network card configuration:
sudo vim /etc/netplan/50-cloud-init.yaml
  • Enter the network card configuration:
network:
    ethernets:
        ens33:   #内网网卡
            dhcp4: false
            addresses: [172.16.0.101/24] #内网IP
            gateway4: 172.16.0.1  #内网网关IP
            nameservers:
                    addresses: [114.114.114.114,172.16.0.2] #内网DNS
        ens34:   #外网网卡 ,单网卡时省略此步骤,若使用Ubuntu 1804,可在系统可视化UI中进行静态IP配置  
            dhcp4: false
            addresses: [192.168.0.101/24]
            gateway4: 192.168.0.1
            nameservers:
                    addresses: [114.114.114.114,192.168.0.2]
    version: 2
  • Application configuration:
sudo netplan apply

Clock synchronization

Each node needs to execute when there are multiple nodes, and execute directly on the node when there is a single node:

#更换时区为东八区
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#安装ntpdate工具
sudo apt-get install ntpdate
#设置系统时间与网络时间同步
sudo ntpdate cn.pool.ntp.org
#然后将时间更新到硬件上:
sudo hwclock --systohc

install rancher

First install rancher on the master node server, here is version 2.3.8:

docker run -d --restart=unless-stopped -p 30080:80 -p 30443:443 -v /home/rancher:/var/lib/rancher/ -e CATTLE_TLS_MIN_VERSION="1.0" rancher/rancher:v2.3.8

After installation, verification is required. Visit http://192.168.0.101:30080 or https://192.168.0.101:30443 to see if you enter the rancher interface. The first time you enter, you need to set a password. After setting the password and logging in, you can enter the cluster management page to add cluster operations

Create a K8S cluster

First click Add Cluster to create a new cluster:
insert image description here
Select the cluster type as Custom:
insert image description here
Enter the cluster name and select the appropriate version:
insert image description here
Click Next to enter the next-level page for cluster option configuration. If it is a single-node deployment, this node needs to be used as three roles. Check the three cluster role options. If it is a multi-node deployment, you can freely assign the role of each server, but you need to pay attention to the three different roles. One exists, and then click the copy button on the lower right to copy the command:
insert image description here
execute the command on the cloud resource server. After the execution is completed, a host will be prompted on the page to join, and then click Finish.
insert image description here
After that, the cluster will enter the creation state, just wait for the creation to complete:
insert image description here
when the server status changes to green ACTIVE, it means the cluster is created successfully.

Guess you like

Origin blog.csdn.net/u012751272/article/details/118859135