How to build kubernetes Cluster Environment in CentOS7
This article introduces how to build a kubernetes cluster environment in CentOS7. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
I. preparation of server environment
192.168.247.128: k8s-master 、 etcd 、 registry
192.168.247.129: k8s-nodeA
192.168.247.130: k8s-nodeB
Note: install the lsb_release command: yum install redhat-lsb-y
The three machines have the same configuration.
Install the same version of docker:
[root@localhost] # docker-v
Docker version 1.12.6, build 85d7426/1.12.6
Modify the hostname on the three machines:
Run on master:
[root@localhost] # hostnamectl-- static set-hostname k8s-master
Run on nodeA:
[root@localhost] # hostnamectl-- static set-hostname k8s-nodeA
Run on nodeB:
[root@localhost] # hostnamectl-- static set-hostname k8s-nodeB
Configure hosts on each of the three machines and execute the following command to modify the hosts file:
Echo '192.168.247.128 k8s-master192.168.247.128 etcd192.168.247.128 registry192.168.247.129 k8s-nodeA192.168.247.130 k8sMurnodeB' > / etc/hosts
Turn off the firewall on the three machines and execute on each of the three machines:
[root@localhost ~] # systemctl stop firewalld
Note: firewall related commands:
View firewall status: systemctl status firewalld
Turn off the firewall: systemctl stop firewalld
Turn on the firewall: systemctl start firewalld
Before closing:
After closing:
Second, install etcd
K8s depends on etcd. You need to install etcd first, and install etcd in yum mode:
Run on k8s-master:
Yum install etcd-y
Edit the configuration file after the installation is completed. The default configuration file for etcd installed by yum is / etc/etcd/etcd.conf.
Modify the following three parameter values:
Start etcd by executing the following command, and verify that the status is correct:
[root@localhost ~] # systemctl start etcd
[root@localhost ~] # etcdctl set developer xiejunbo
Xiejunbo
[root@localhost ~] # etcdctl get developer
Xiejunbo
[root@localhost] # etcdctl-C http://etcd:4001 cluster-health
Member 8e9e05c52164694d is healthy: got healthy result from http://etcd:2379
Cluster is healthy
[root@localhost] # etcdctl-C http://etcd:2379 cluster-health
Member 8e9e05c52164694d is healthy: got healthy result from http://etcd:2379
Cluster is healthy
It shows that the ectd is healthy and can be used normally.
3. Deploy k8s-master
Install docker:
Yum install docker
Modify the docker configuration file: vi / etc/sysconfig/docker
Set docker to boot automatically, and then enable the docker service:
[root@localhost ~] # chkconfig docker on
[root@localhost ~] # service docker start
Install kubernetes:
Install kubernetes: yum install kubernetes using yum
After the kubernetes installation is successful, configure and start kubernetes:
The following components are required to run on kubernetes master:
1.kubernetes api server
2.kubernetes controller manager
3.kubernetes scheduler
The corresponding configuration file needs to be modified:
/ etc/kubernetes/apiserver: modify four parameters:
/ etc/kubernetes/config: modify a parameter:
After the modification is completed, start the service, and then set the boot self-startup:
[root@localhost ~] # systemctl enable kube-apiserver.service
Created symlink from / etc/systemd/system/multi-user.target.wants/kube-apiserver.service to / usr/lib/systemd/system/kube-apiserver.service.
[root@localhost ~] # systemctl start kube-apiserver.service
[root@localhost ~] # systemctl enable kube-controller-manager.service
Created symlink from / etc/systemd/system/multi-user.target.wants/kube-controller-manager.service to / usr/lib/systemd/system/kube-controller-manager.service.
[root@localhost ~] # systemctl start kube-controller-manager.service
[root@localhost ~] # systemctl enable kube-scheduler.service
Created symlink from / etc/systemd/system/multi-user.target.wants/kube-scheduler.service to / usr/lib/systemd/system/kube-scheduler.service.
[root@localhost ~] # systemctl start kube-scheduler.service
IV. Deploy k8s-node
1. Install docker strategy
2.nodeA node installs kubernetes: yum install kubernetes
Configure and start kubernetes:
The following components need to be run on k8s-node:
1.kubelet
2.kubernetes proxy
Two configuration files need to be modified accordingly:
Modify the kube_master address parameter in / etc/kubernetes/config:
Modify the three parameters in / etc/kubernetes/kubelet:
After the modification is completed, start the service and set the boot to start automatically:
[root@localhost ~] # systemctl enable kubelet.service
Created symlink from / etc/systemd/system/multi-user.target.wants/kubelet.service to / usr/lib/systemd/system/kubelet.service.
[root@localhost ~] # systemctl start kubelet.service
[root@localhost ~] # systemctl enable kube-proxy.service
Created symlink from / etc/systemd/system/multi-user.target.wants/kube-proxy.service to / usr/lib/systemd/system/kube-proxy.service.
[root@localhost ~] # systemctl start kube-proxy.service
After the node starts, check the master to see if the status is normal:
[root@localhost ~] # kubectl-s http://k8s-master:8080 get node
NAME STATUS AGE
K8s-nodea Ready 2m
[root@localhost ~] # kubectl get nodes
NAME STATUS AGE
K8s-nodea Ready 7m
Press nodeA on the node k8s-nodeB, and also install kubernetes:
After installing kubernetes successfully, press k8s-nodeA to modify the configuration:
After modifying the configuration, start the service and set the boot self-startup:
[root@localhost ~] # systemctl enable kubelet.service
Created symlink from / etc/systemd/system/multi-user.target.wants/kubelet.service to / usr/lib/systemd/system/kubelet.service.
[root@localhost ~] # systemctl start kubelet.service
[root@localhost ~] # systemctl enable kube-proxy.service
Created symlink from / etc/systemd/system/multi-user.target.wants/kube-proxy.service to / usr/lib/systemd/system/kube-proxy.service.
[root@localhost ~] # systemctl start kube-proxy.service
View the node and node status in the cluster on master:
Create a Flannel network
Install Flannel on k8s-master, k8s-nodeA, k8s-nodeB, and execute the command:
Yum install flannel
After successful installation, the configuration files on k8s-master, k8s-nodeA and k8s-nodeB are all modified to: / etc/sysconfig/flanneld
Configure the key about flannel in etcd in k8s-master:
[root@localhost ~] # etcdctl mk / atomic.io/network/config'{"Network": "192.0.0.0Univer 16"}'
{"Network": "192.0.0.0Can 16"}
Special note: Flannel uses Etcd for configuration to ensure configuration consistency among multiple Flannel instances, so you need to configure the following on etcd: (the key of'/ atomic.io/network/config' corresponds to the configuration item FLANNEL_ETCD_PREFIX in / etc/sysconfig/flannel above. If there is an error, startup will make an error)
After starting Flannel, you need to restart docker and kubernete in turn:
Execute on master:
Systemctl enable flanneld.service systemctl start flanneld.service service docker restartsystemctl restart kube-apiserver.servicesystemctl restart kube-controller-manager.servicesystemctl restart kube-scheduler.service
Execute on node:
Systemctl enable flanneld.service systemctl start flanneld.service service docker restartsystemctl restart kubelet.servicesystemctl restart kube-proxy.service
Installation and configuration complete
=
Check the K8S version:
So much for sharing about how to build a kubernetes cluster environment in CentOS7. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.