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