Kubernetes installation and Construction II (binary file)

1, Install via binary tool

This example also deploys three nodes, 1master and 2 nodes.

1. Preparation

1.1 download installation package

The download address of Kubernetes binary file is:

https://github.com/kubernetes/kubernetes/releases

K8s divides binary packages into Client Binaries, Server Binaries and Node Binaries, which are Client Binaries, Master Node Binaries and Node Binaries respectively.

For this example, we need to download kubernetes-server-linux-amd64 tar. gz,kubernetes-node-linux-amd64.tar.gz and kubernetes client Linux amd 64 tar. GZ [can not be downloaded separately], and the path is usually / opt.

cd /opt
wget https://dl.k8s.io/v1.13.4/kubernetes-server-linux-amd64.tar.gz
wget https://dl.k8s.io/v1.13.4/kubernetes-node-linux-amd64.tar.gz

Download etcd binaries

wget https://github.com/etcd-io/etcd/releases/download/v3.3.12/etcd-v3.3.12-linux-amd64.tar.gz

###1.2 turn off firewall and SELinux

All nodes:

systemctl stop firewalld && systemctl disable firewalld
setenforce 0

Edit / etc/selinux/config

SELINUX=disabled

1.3 disable switching partitions

Disable all CentOS partitions

swapoff -a && sysctl -w vm.swappiness=0

Modify / etc/fstab to exchange the file system comments corresponding to the partition

#/dev/mapper/centos-swap swap        swap    defaults      0 0

1.4 setting network parameters required by Docker

Docker is only installed on node, and / etc / sysctl d/k8s. Conf, add:

net.ipv4.ip_forward=1

Execution:

sysctl -p /etc/sysctl.d/k8s.conf

###1.5 configure the yum installation source of Docker

We have an artifact warehouse. We can use the rpm source / docker source of the artifact.

Assuming that there is no Docker yum source on the default CentOs, use the following command to add it:

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Use Yum config manager to manage and configure the software warehouse of CentOS. If not, install with the following command:

yum install yum-utils

1.6 installing Docker

After setting the software source, you can install Docker CE using yum:

yum install docker-ce

Start:

systemctl enable docker
systemctl start docker 

###1.7 create installation directory

Install k8s in the / k8s directory. First create several related directories

mkdir -p /k8s/etcd/bin /k8s/etcd/cfg
mkdir -p /k8s/kubernetes/bin /k8s/kubernetes/cfg /k8s/kubernetes/ssl

2. Deploy etcd

Unzip the previously downloaded etcd-v3 3.12-linux-amd64. tar. gz:

tar -xvf etcd-v3.3.12-linux-amd64.tar.gz

Then copy etcd and etcdctl to / k8s/etcd/bin

cp etcd-v3.3.12-linux-amd64/etcd etcd-v3.3.12-linux-amd64/etcdctl /k8s/etcd/bin/

Configure etcd. You need to create etcd configuration files on three hosts. The only difference is the IP address.

Master node

vi /k8s/etcd/cfg/etcd
#The contents are as follows
# [Member]
ETCD_NAME="etcd01"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.1.121:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.1.121:2379"
# [Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.121:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.121:2379"
ETCD_INITAL_CLUSTER="etcd01=http://192.168.1.121:2380,etcd02=http://192.168.1.122:2380,etcd3=http://192.168.1.123:2380"
ETCD_INITAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITAL_CLUSTER_STATE="new"

Next is Node 1. Create a configuration file:

vim /k8s/etcd/cfg/etcd

The contents are as follows:

# [Member]
ETCD_NAME="etcd02"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.1.122:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.1.122:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.122:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.122:2379"
ETCD_INITIAL_CLUSTER="etcd01=http://192.168.1.121:2380,etcd02=http://192.168.1.122:2380,etcd03=http://192.168.1.123:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

Node 2 refers to the above configuration.

Then create the etcd system service unit file. Since the installation location of etcd is exactly the same in the three nodes, the etcd system service unit files of the three nodes are exactly the same.

Execute on all nodes:

vim /lib/systemd/system/etcd.service

The contents are as follows:

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=/k8s/etcd/cfg/etcd
ExecStart=/k8s/etcd/bin/etcd \
--name=${ETCD_NAME} \
--data-dir=${ETCD_DATA_DIR} \
--listen-peer-urls=${ETCD_LISTEN_PEER_URLS} \
--listen-client-urls=${ETCD_LISTEN_CLIENT_URLS}, http://127.0.0.1:2379 \
--advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} \
--initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
--initial-cluster=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-token=${ETCD_INITIAL_CLUSTER_TOKEN} \
--initial-cluster-state=new
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

Finally, start the etcd service at three nodes

systemctl enable etcd
systemctl start etcd

After configuration, verify whether the cluster is normal

/k8s/etcd/bin/etcdctl cluster-health

TIPS: all nodes need to be started at the same time when starting the cluster.

3. Deploy flannel network

Download the binary files of flannel on two nodes:

https://github.com/coreos/flannel/releases

The downloaded file name is etcd-v3 3.12-linux-amd64. tar. gz
tar zxvf decompression
Unzip flanneld and MK docker opts SH copy to / k8s/kubernetes/bin/

cp flanneld mk-docker-opts.sh /k8s/kubernetes/bin/

Create flannel configuration file / k8s/kubernetes/cfg/flanneld

FLANNEL_OPTIONS="--etcd-endpoints=http://192.168.1.121:2379,http://192.168.1.122:2379,http://192.168.1.123:2379"

Write Pod network information in etcd cluster

/k8s/etcd/bin/etcdctl set /coreos.com/network/config '{ "Network": "172.18.0.0/16", "Backend":{"Type": "vxlan"}}'

Create the system service unit file of flannel / lib / SYSTEMd / system / flanneld service

[Unit]
Description=Flanneld overlay address etcd agent
After=network-online.target network.target
Before=docker.service

[Service]
Type=notify
EnvironmentFile=/k8s/kubernetes/cfg/flanneld
ExecStart=/k8s/kubernetes/bin/flanneld --ip-masq $FLANNEL_OPTIONS
ExecStartPost=/k8s/kubernetes/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env
Restart=on-failure

[Install]
WantedBy=multi-user.target

Start the flannel service

systemctl enable flanneld
systemctl start flanneld

4. Deploy the Master node

Keywords: Kubernetes

Added by bothwell on Tue, 08 Mar 2022 07:32:12 +0200