Installation of Kubernetes 1.15 full version under centos7

Keywords: yum Kubernetes Docker kubelet

Introduction to Kubernetes

Kubernetes (K8S) is an open source container cluster management system, which can realize the functions of automatic deployment, automatic expansion and maintenance of container cluster. It is not only a container layout tool, but also a new distributed architecture leading scheme based on container technology. On the basis of Docker technology, it provides deployment and operation, resource scheduling, service discovery and dynamic scaling functions for container applications, which improves the convenience of large-scale container cluster management.

There are two types of K8S cluster: management node and working node. The management node is mainly responsible for K8S cluster management, information exchange and task scheduling among nodes in the cluster, and life cycle management of containers, Pod, NameSpaces, PV, etc. Work nodes mainly provide computing resources for containers and pods. Pod and containers all run on work nodes. Work nodes communicate with management nodes through kubelet services to manage the life cycle of containers and communicate with other nodes in the cluster.

Tip: master and open key login

ssh-keygen
ssh-copy-id root@192.168.3.71
ssh-copy-id root@192.168.3.72

Installation Environment Configuration (Next step needs to be performed on all hosts)

1. Before installation, the following preparations should be made. Three CentOS 7 hosts are as follows (more or less can be determined by themselves, at least two or more):
Setting Host Names on Autonomous Machines
192.168.3.70

#hostnamectl set-hostname master

Or modify the configuration file to permanently modify your host name, and modify the file by following steps

cat >> /etc/sysconfig/network << EOF

hostname=master

EOF

2. Edit / etc/hosts file and add domain name resolution.

cat <<EOF >>/etc/hosts

192.168.3.70 master
192.168.3.71 node1
192.168.3.72 node2

EOF

3. Close firewalls, selinux and swap.

systemctl stop firewalld

systemctl disable firewalld

setenforce 0

sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

swapoff -a

sed -i 's/.*swap.*/#&/' /etc/fstab

4. The first installation opened the routing and forwarding function, many documents were not written, but I did report a mistake when I installed it.

 echo "1" > /proc/sys/net/ipv4/ip_forward

5. Configure kernel parameters to transfer bridged IPv4 traffic to the chain of iptables

cat > /etc/sysctl.d/k8s.conf <<EOF

net.bridge.bridge-nf-call-ip6tables = 1
    
net.bridge.bridge-nf-call-iptables = 1
    
EOF

Make it effective

sysctl --system

6. Configuring domestic yum sources

yum install -y wget

mkdir /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo

yum clean all && yum makecache

Configuration of domestic Kubernetes sources

cat <<EOF > /etc/yum.repos.d/kubernetes.repo

[kubernetes]

name=Kubernetes

baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/

enabled=1

gpgcheck=1

repo_gpgcheck=1

gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

EOF

Configure docker source

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

3. Start installing docker, kubeadm, kubectl, kubelet

1. Install docker

yum install -y docker-ce-18.06.1.ce-3.el7

systemctl enable docker && systemctl start docker

docker version

2. Install kubeadm, kubelet, kubectl

yum install -y kubelet kubeadm kubectl

systemctl enable kubelet

IV. master Deployment
Tip: Execute on master node
1. Initialize Kubernetes cluster in master.

kubeadm init --kubernetes-version=1.15.0 --apiserver-advertise-address=192.168.3.70 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

apiserver-advertise-address=192.168.3.70 (master address)

Finally, token is generated as follows

kubeadm join 192.168.3.70:6443 --token kekvgu.nw1n76h84f4camj6 \

--discovery-token-ca-cert-hash sha256:4ee74205227c78ca62f2d641635afa4d50e6634acfaa8291f28582c7e3b0e30e

2. Configuring the kubectl tool

The system starts kubernetes from admin.conf file, and it won't work if it's not configured.

mkdir -p /root/.kube

cp /etc/kubernetes/admin.conf /root/.kube/config

kubectl get nodes # Look at all the nodes in the cluster, and it's still not read because the flannel network has not been deployed yet.

3. Deployment of flannel network

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml

5. node deployment

Execute the token section we generated on master directly on each node

kubeadm join 192.168.3.70:6443 --token kekvgu.nw1n76h84f4camj6 \

--discovery-token-ca-cert-hash sha256:4ee74205227c78ca62f2d641635afa4d50e6634acfaa8291f28582c7e3b0e30e

At this point, the cluster deployment is complete and the status of nodes can be obtained on the master

kubectl get nodes -o wide

Explain the successful deployment for read.

Posted by mdkelly_komex on Sun, 21 Jul 2019 04:34:35 -0700