您好,登錄后才能下訂單哦!
這篇文章給大家介紹怎么在centos 7系統中安裝配置k8s集群,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
配置背景介紹
kubernetes是google開源的容器集群管理系統,提供應用部署、維護、擴展機制等功能,利用kubernetes能方便管理跨集群運行容器化的應用,簡稱:k8s(k與s之間有8個字母)
實驗環境
centos7.3 64位
安裝
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
修改配置文件
注意下面的10.135.163.237換成自己服務器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
修改host
vi /etc/hosts 10.135.163.237 k8s_master
添加網絡
systemctl enable etcd.service systemctl start etcd.service etcdctl mk //atomic.io/network/config '{"Network":"172.17.0.0/16"}'
啟動服務
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;
第一個demo
編寫文件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
編寫文件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
創建服務
kubectl create -f a.yaml --validate kubectl create -f b.yaml --validate
刪除服務
kubectl delete -f a.yaml kubectl delete -f b.yaml
增加子節點
安裝軟件
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
修改配置文件(10.135.163.237為主節點ip,139.199.0.29為當前節點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
啟動服務
service docker start for SERVICES in kube-proxy kubelet docker flanneld; do systemctl restart $SERVICES systemctl enable $SERVICES systemctl status $SERVICES done;
在主服務器查看節點
kubectl get node
重啟服務(重新加入集群)
systemctl restart kube-apiserver.service
刪除節點
kubectl delete node 節點ip
關于怎么在centos 7系統中安裝配置k8s集群就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。