Author: Wang Zhiyi

Source: Hang Seng LIGHT Cloud Community

Procedure For installing a single node

A, environmental

A physical machine or vm that runs RedHat7.2

Second, preparation

1. Disable the RedHat firewall systemctl disable firewalld to avoid conflicts with the docker iptables

systemctl stop firewalld

Installation and configuration

Install etCD and Kubernetes

yum -y install etcd kubernetes

The above command will automatically install Docker when kubernetes is installed

2, configuration kubernetes apiserver (vi/etc/kubernetes/apiserver)

Delete ServiceAccount from KUBE_ADMISSION_CONTROLCopy the code

3. Configure docker and set docker accelerator

Because the docker image download mode is downloaded from the Docker Hub, it is very slow and often times out the connection request, so the accelerator must be set. We can register an account in Aliyun or DaoCloud to authenticate and select the accelerator, which will generate our own accelerator address. I am DaoCloud registered, such as https://o18pfdk4.mirror.aliyuncs.com. (Settings of Docker accelerator in different systems)Copy the code

OPTIONS=’–selinux-enabled=false –insecure-registry gcr. IO –registry-mirror=https://o18pfdk4.mirror.aliyuncs.com’

4. Start all related services in sequence

systemctl start etcd systemctl start docker systemctl start kube-apiserver systemctl start kube-controller-manager Systemctl start kube – the scheduler systemctl start kubelet systemctl start kube – proxy can ps – ef | grep kub to see if the service. At this point, our standalone (single-node) kubernetes deployment is complete

Multi-node Installation

A, environmental

Create three RedHat7.2 VMS, one for the master host, and the other two for nodes. Assume that the IP address of host master is 192.168.100.50 node1:192.168.100.51 Node2:192.168.100.52

Second, preparation

1. Set the host names of the three VMS

Hostnamectl set-hostname hostname: k8s-master k8s-node1 k8s-node2

2. Modify the hosts file

Add the following information to the hosts (vi /etc/hosts) files of the three VMS: 192.168.100.50k8s-mst 192.168.100.51k8s-nod1 192.168.100.52k8s-nod2

3. To avoid conflicts with Docker iptables, disable the firewall on Node

systemctl stop firewalld systemctl disable firewalld

4. To keep the time of each node consistent, you need to install NTP for all nodes

yum -y install ntp systemctl start ntpd systemctl enable ntpd

Install and configure K8S-MST

1. Install Kubernetes and etCD

yum -y install kubernetes etcd

Kubectl – -version # Kubernetes v1.4.0

Etcd (vi /etc/etcd/etcd.conf)

ETCD_NAME = default ETCD_DATA_DIR = "/ var/lib/etcd/default etcd" ETCD_LISTEN_CLIENT_URLS = "http://0.0.0.0:2379" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost:2380" ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"

3, configuration kube – apiserver (vi/etc/kubernetes/apiserver)

KUBE_API_ADDRESS = "-- address = 0.0.0.0" KUBE_ETCD_SERVERS = "-- etcd - the servers = http://127.0.0.1:2379" KUBE_SERVICE_ADDRESSES = "- service - cluster - IP - range = 10.254.0.0/16"Copy the code

4. Set up docker accelerator

Create a shell file to start these services

#file name: k8s-mst.shfor SERVICE in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart SERVICE systemctl enable SERVICE done

Add execute permission and start the service

chmod 744 k8s-mst.sh ./k8s-master.sh

Start etCD, kube-Apiserver, kube-Controller-Manager and kube-scheduler

6. Configure the Flannel network on etCD

Etcdctl mk/flannel/network/config "{" network" : "172.17.0.0/16"} '

4. Install and configure NODE

1. Co-configure on K8S-NOD1 and K8S-NOD2

1.1. Install Kubernetes and Flannel

Yum -y install kubernetes flanne yum -y install kubernetes flanne yum -y install kubernetes flanne yum -y install kubernetes flanne FLANNEL_ETCD_ENDPOINTS = “http://192.168.100.50:2379” FLANNEL_ETCD_PREFIX = “/ flannel/network” FLANNEL_OPTIONS = “– iface = enp33″ note: Kubernetes (vi /etc/kubernetes/config) KUBE_LOGTOSTDERR=”–logtostderr=true” KUBE_LOG_LEVEL = “- v = 0” KUBE_ALLOW_PRIV = “– allow – ring = false” KUBE_MASTER = “– master = http://192.168.100.50:8080”

1.4. Set the Docker accelerator

2. Only in k8S-NOd1 configuration

Kubelet (vi /etc/kubernetes/kubelet) KUBELET_ADDRESS=”–address=0.0.0.0″ KUBELET_HOSTNAME = “- the hostname – override = k8s – nod1” KUBELET_API_SERVER = “- API – the servers = http://192.168.100.50:8080”

3. Only in k8S-NOD2 configuration

Kubelet (vi /etc/kubernetes/kubelet) KUBELET_ADDRESS=”–address=0.0.0.0″ KUBELET_HOSTNAME = “- the hostname – override = k8s – nod2” KUBELET_API_SERVER = “- API – the servers = http://192.168.100.50:8080”

4. Start Flanneld, Kube-proxy, Kubelet and Docker services on K8S-NOd1 and K8S-NoD-2

Still create a SHel file to start these services

#file name: k8s-node.sh

for SERVICE in flanneld kube-proxy kubelet docker;

do

systemctl restart $SERVICE

systemctl enable $SERVICE

systemctl status $SERVICE

Done Add the execute permission and run the chmod 744 k8s-node./k8s-node command. After the services of k8S-nod1 and k8S-nod2 are enabled, Kubectl get Nodes: NAME STATUS AGE K8S-NOd1 Ready 3h k8S-NOD2 Ready 2h

5. Add and delete nodes

1. Delete the node

Method 1: Perform cluster scheduling isolation on nodes

#file name: unschedule_node.yamlapiVersion: v1
kind: Node
matadata:
name: k8s-nod1
labels:
kubernetes.io/hostname: k8s-nod1
spec:
unschedulable: true
kubectl replace -f unschedule_node.yaml
Copy the code

Kubectl patch node k8s-nod1 -p ‘{” spec: “:{” unschedulable” :true}}’ kubectl Cordon k8s-nod1 Kubectl delete node k8s-nod1: Kubectl delete node k8s-nod1: Kubectl delete node k8s-nod1: kubectl delete node k8s-nod1

2. Add a node

Method 1: Restore the isolated node kubectl uncordon k8s-nod1 Method 2: add a new physical node to the K8S cluster. 1. RHSM certificate (Node image pulling) Node download rpmfind.net/linux/cento…