Detailed steps to install and configure k8s cluster in centos 7

Configuration background introduction

kubernetes is Google's open source container cluster management system. It provides functions such as application deployment, maintenance, and expansion mechanism. Using kubernetes can facilitate the management of cross-cluster containerized applications, referred to as k8s (there are 8 letters between k and s)

Why use kubernetes such a complicated docker cluster management tool? I first came into contact with docker's built-in swarm, this tool is very simple and quick to complete the docker cluster function. However, when using the built-in swarm of docker1.13 as a cluster, I encountered VIP[Load Balancing] (https://cloud.tencent.com/product/clb?from=10680) not correctly mapping the port to the external network, or the address was occupied. This is not good for the high availability requirements. However, I didn't find a solution, so I could only switch to k8s.

lab environment

installation

yum-config-manager --add-repo https://docs.docker.com/v1.13/engine/installation/linux/repo_files/centos/docker.repo 
yum makecache fast 
yum -y install docker-engine-1.13.1 
yum install epel-release -y 
yum remove -y docker-engine* 
yum install -y kubernetes etcd docker flannel 

Modify configuration file

Note that the 10.135.163.237 below is replaced with your own server ip

sed -i "s/localhost:2379/10.135.163.237:2379/g"/etc/etcd/etcd.conf

sed -i "s/localhost:2380/10.135.163.237:2380/g"/etc/etcd/etcd.conf

sed -i "s/10.135.163.237:2379/10.135.163.237:2379,http:\/\/127.0.0.1:2379/g"/etc/etcd/etcd.conf

sed -i "s/127.0.0.1:2379/10.135.163.237:2379/g"/etc/kubernetes/apiserver

sed -i "s/--insecure-bind-address=127.0.0.1/--insecure-bind-address=0.0.0.0/g"/etc/kubernetes/apiserver

sed -i "s/--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota/--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota/g"/etc/kubernetes/apiserver

sed -i "s/--hostname-override=127.0.0.1/--hostname-override=10.135.163.237/g"/etc/kubernetes/kubelet

sed -i "s/127.0.0.1:8080/10.135.163.237:8080/g"/etc/kubernetes/kubelet

sed -i "s/--address=127.0.0.1/--address=0.0.0.0/g"/etc/kubernetes/kubelet

sed -i "s/127.0.0.1:8080/10.135.163.237:8080/g"/etc/kubernetes/config

sed -i "s/127.0.0.1:2379/10.135.163.237:2379/g"/etc/sysconfig/flanneld 

Modify host

vi /etc/hosts 
10.135.163.237 k8s_master 

Add network

systemctl enable etcd.service

systemctl start etcd.service

etcdctl mk //atomic.io/network/config '{"Network":"172.17.0.0/16"}' 

Start service

service docker start 
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet docker flanneld ;do systemctl restart $SERVICES; systemctl enable $SERVICES; systemctl status $SERVICES; done;

The first demo

Write file a.yaml

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
 name: my-app
spec: 
 replicas:2
 template:
 metadata:
 labels:
 app: my-app
 spec:
 containers:- name: my-app
 image: registry.alauda.cn/yubang/paas_base_test
 ports:- containerPort:80
 command:["/bin/bash","/var/start.sh"] 
 resources: 
 limits: 
 cpu:0.5 
 memory: 64Mi 

Write file b.yaml

apiVersion: v1 
kind: Service 
metadata: 
 name: my-app-svc
 labels:
 app: my-app
spec: 
 ports:- port:80
 targetPort:80
 nodePort:30964
 type: NodePort
 selector:
 app: my-app

Create service

kubectl create -f a.yaml --validate 
kubectl create -f b.yaml --validate 

Delete service

kubectl delete-f a.yaml 
kubectl delete-f b.yaml 

Add child nodes

install software

yum-config-manager --add-repo https://docs.docker.com/v1.13/engine/installation/linux/repo_files/centos/docker.repo 
yum makecache fast 
yum -y install docker-engine-1.13.1 
yum install epel-release -y 
yum remove -y docker-engine* 
yum install -y kubernetes docker flannel 

Modify the configuration file (10.135.163.237 is the main node ip, 139.199.0.29 is the current node ip)

sed -i "s/--hostname-override=127.0.0.1/--hostname-override=139.199.0.29/g"/etc/kubernetes/kubelet

sed -i "s/127.0.0.1:8080/10.135.163.237:8080/g"/etc/kubernetes/kubelet

sed -i "s/--address=127.0.0.1/--address=0.0.0.0/g"/etc/kubernetes/kubelet

sed -i "s/127.0.0.1:8080/10.135.163.237:8080/g"/etc/kubernetes/config

sed -i "s/127.0.0.1:2379/10.135.163.237:2379/g"/etc/sysconfig/flanneld

sed -i "s/--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota/--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota/g"/etc/kubernetes/apiserver

Start service

service docker start

for SERVICES in kube-proxy kubelet docker flanneld;do 
 systemctl restart $SERVICES
 systemctl enable $SERVICES
 systemctl status $SERVICES
 done;

View nodes on the main server

kubectl get node 

Restart the service (rejoin the cluster)

systemctl restart kube-apiserver.service 

Delete node

kubectl delete node node ip

to sum up

The above is the entire content of this article. I hope that the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message and exchange. Thank you for your support to ZaLou.Cn.

Recommended Posts

Detailed steps to install and configure k8s cluster in centos 7
Install and configure FreeIPA in Centos7
Detailed steps to install virtual machines with VMware 15 and use CentOS 8
How to install and configure Elasticsearch on CentOS 7
How to install and configure VNC on CentOS 8
How to install and configure Redis on CentOS 8
How to install and configure phpMyAdmin on CentOS 6
How to install and configure Owncloud on CentOS 8
How to install and configure Redmine on CentOS 8
Centos6.5 install and configure mongodb
Centos7 install k8s cluster 1.15.0 version
How to install and configure NFS server on CentOS 8
Detailed steps to configure Ubuntu 16.04 and Apache virtual host
Detailed steps to install centos on vmware10.0 cracked version
Install and configure keepalived under CentOS 5.9
How to upgrade CentOS7 to CentOS8 (detailed steps)
How to install and configure Postfix mail server on CentOS8
Linux CentOS 7 install JDK detailed steps
Install and configure Docker in Ubuntu
CentOS7.3 install iptables and detailed use
CentOS 8 - install and configure NFS service
How to install HDP2.6 in Centos7.2
CentOS Minimal install and configure TIPS
CentOS 6.8 method steps to install vsftpd
Detailed steps to install MySQL to change the default password in Ubuntu
Centos8 uses Apache httpd2.4.37 to install web server steps in detail
k8s practice (1): Centos 7.6 deployment k8s (v1.14.2) cluster
CentOS7.3.1611 deploys k8s1.5.2 cluster
CentOS7 deploys k8s cluster
Centos7 deploys Kubernetes cluster
Detailed steps to install and configure k8s cluster in centos 7
Centos7 install k8s cluster 1.15.0 version
Centos7 hadoop cluster installation and configuration
How to install Android SDK in centos7
Deploy Docker and configure Nginx in CentOS
Compile and install nodejs and yum in Centos8
Install nginx in centos8 custom directory (detailed tutorial)
How to install and configure NATS on Ubuntu 16.04
How to install and configure Gogs on Ubuntu 18.04
VMware Fusion install CentOS7 and configure the network
How to install and use Docker on CentOS 7
How to install and configure Cyberpanel on Ubuntu 18.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
Configure centos container to support ssh in Docker
How to install and configure GitLab on Ubuntu 18.04
How to install and configure Ansible on Ubuntu 18.04
Detailed steps to install Anaconda on Linux (Ubuntu 18.04)
How to install and use Composer on CentOS 8
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install Node.js and npm on CentOS 8
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install php7.3 in centos8 custom directory
How to install and use Curl on CentOS 8
Centos7.2 compile and install way to build phpMyAdmin
How to install and configure AppScale on Ubuntu 12.04
How to install and uninstall tomcat on centos
How to install and configure PostGIS on Ubuntu 14.04
Install centos7 and connect
Install MySQL5.7 in centos7
CentOS7.3.1611 deploys k8s1.5.2 cluster
Install php in centos
CentOS 7 install vsftpd steps