這篇文章給大家介紹CentOS7中怎么搭建kubernetes集群環(huán)境,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
目前成都創(chuàng)新互聯(lián)已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁(yè)空間、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、臺(tái)山網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶(hù)導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶(hù)和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
一、服務(wù)器環(huán)境準(zhǔn)備
192.168.247.128 : k8s-master、etcd、registry
192.168.247.129 : k8s-nodeA
192.168.247.130 : k8s-nodeB
注:安裝lsb_release命令:yum install redhat-lsb -y
三臺(tái)機(jī)器配置相同
安裝好相同版本的docker:
[root@localhost ~]# docker -v
Docker version 1.12.6, build 85d7426/1.12.6
三臺(tái)機(jī)器上分別修改hostname:
master上運(yùn)行:
[root@localhost ~]# hostnamectl --static set-hostname k8s-master
nodeA上運(yùn)行:
[root@localhost ~]# hostnamectl --static set-hostname k8s-nodeA
nodeB上運(yùn)行:
[root@localhost ~]# hostnamectl --static set-hostname k8s-nodeB
三臺(tái)機(jī)器上分別配置hosts, 執(zhí)行如下命令修改hosts文件:
echo '192.168.247.128 k8s-master 192.168.247.128 etcd 192.168.247.128 registry 192.168.247.129 k8s-nodeA 192.168.247.130 k8s-nodeB' >> /etc/hosts
關(guān)閉三臺(tái)機(jī)器的防火墻, 三臺(tái)機(jī)器上分別執(zhí)行:
[root@localhost ~]# systemctl stop firewalld
注:防火墻相關(guān)命令:
查看防火墻狀態(tài): systemctl status firewalld
關(guān)閉防火墻:systemctl stop firewalld
開(kāi)啟防火墻:systemctl start firewalld
關(guān)閉前:
關(guān)閉后:
二、安裝etcd
k8s運(yùn)行依賴(lài)etcd,需要先安裝etcd, yum方式安裝etcd:
在k8s-master上運(yùn)行:
yum install etcd -y
安裝完成后編輯配置文件 , yum安裝的etcd默認(rèn)配置文件在/etc/etcd/etcd.conf
修改如下三個(gè)參數(shù)值:
執(zhí)行如下命令,啟動(dòng)etcd, 并驗(yàn)證狀態(tài)是否正確 :
[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
說(shuō)明ectd狀態(tài)健康,可以正常使用。
三、部署k8s-master
安裝docker:
yum install docker
修改docker配置文件:vi /etc/sysconfig/docker
設(shè)置docker開(kāi)機(jī)自啟動(dòng),然后開(kāi)啟docker服務(wù):
[root@localhost ~]# chkconfig docker on
[root@localhost ~]# service docker start
安裝kubernetes :
使用yum方式安裝kubernetes: yum install kubernetes
kubernetes安裝成功后, 配置并啟動(dòng)kubernetes :
在kubernetes master 上運(yùn)行需要以下組件:
1.kubernetes api server
2.kubernetes controller manager
3.kubernetes scheduler
需要修改相對(duì)應(yīng)的配置文件 :
/etc/kubernetes/apiserver: 修改四個(gè)參數(shù):
/etc/kubernetes/config: 修改一個(gè)參數(shù):
修改完成后,啟動(dòng)服務(wù),然后設(shè)置開(kāi)機(jī)自啟動(dòng):
[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
四、部署k8s-node
1.安裝docker略
2.nodeA節(jié)點(diǎn)安裝kubernetes: yum install kubernetes
配置并啟動(dòng)kubernetes:
在k8s-node上需要運(yùn)行以下組件:
1.kubelet
2.kubernetes proxy
需要對(duì)應(yīng)修改兩個(gè)配置文件 :
修改/etc/kubernetes/config中的kube_master地址參數(shù):
修改/etc/kubernetes/kubelet中的三個(gè)參數(shù):
修改完成后,啟動(dòng)服務(wù)并設(shè)置開(kāi)機(jī)自動(dòng)啟動(dòng):
[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
節(jié)點(diǎn)啟動(dòng)后,在master上查看狀態(tài)是否正常:
[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
在節(jié)點(diǎn)k8s-nodeB上按nodeA操作,同樣安裝kubernetes:
安裝kubernetes 成功后, 按k8s-nodeA修改配置:
修改完配置后,啟動(dòng)服務(wù)并設(shè)置開(kāi)機(jī)自啟動(dòng):
[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
在master上查看集群中節(jié)點(diǎn)及節(jié)點(diǎn)狀態(tài):
五、創(chuàng)建Flannel網(wǎng)絡(luò)
在k8s-master、k8s-nodeA、k8s-nodeB上均安裝Flannel, 執(zhí)行命令:
yum install flannel
安裝成功后,k8s-master、k8s-nodeA、k8s-nodeB上均修改配置文件為 :/etc/sysconfig/flanneld
k8s-master中配置etcd中關(guān)于flannel的key:
[root@localhost ~]# etcdctl mk /atomic.io/network/config '{"Network":"192.0.0.0/16"}'
{"Network":"192.0.0.0/16"}
特別注意:Flannel使用Etcd進(jìn)行配置,來(lái)保證多個(gè)Flannel實(shí)例之間的配置一致性,所以需要在etcd上進(jìn)行如下配置:(‘/atomic.io/network/config’這個(gè)key與上文/etc/sysconfig/flannel中的配置項(xiàng)FLANNEL_ETCD_PREFIX是相對(duì)應(yīng)的,錯(cuò)誤的話啟動(dòng)就會(huì)出錯(cuò))
啟動(dòng)Flannel之后,需要依次重啟docker、kubernete:
在master執(zhí)行:
systemctl enable flanneld.service systemctl start flanneld.service service docker restart systemctl restart kube-apiserver.service systemctl restart kube-controller-manager.service systemctl restart kube-scheduler.service
在node上執(zhí)行:
systemctl enable flanneld.service systemctl start flanneld.service service docker restart systemctl restart kubelet.service systemctl restart kube-proxy.service
安裝配置完成
===========================================================
檢查K8S版本:
關(guān)于CentOS7中怎么搭建kubernetes集群環(huán)境就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
標(biāo)題名稱(chēng):CentOS7中怎么搭建kubernetes集群環(huán)境
URL分享:http://aaarwkj.com/article48/iggehp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、定制開(kāi)發(fā)、面包屑導(dǎo)航、小程序開(kāi)發(fā)、虛擬主機(jī)、微信公眾號(hào)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
全網(wǎng)營(yíng)銷(xiāo)推廣知識(shí)