Docker實(shí)踐—CentOS7上部署Kubernetes詳解
Kubernetes架構(gòu)
Kubernetes的整體架構(gòu)如下:

Master為主控節(jié)點(diǎn),上面運(yùn)行apiserver,scheduler,controller-manager等組件。Minion相當(dāng)于工作節(jié)點(diǎn),上面運(yùn)行kubelet,proxy,cAdvisor以及最重要的docker等組件。下面來(lái)實(shí)際部署一下這套集群管理工具。
環(huán)境
yy1 10.193.6.35
yy2 10.193.6.36
yy1作為master,yy2作為minion。
# cat /etc/centos-release
CentOS Linux release 7.0.1406 (Core)
安裝kubernetes
# curl https://copr.fedoraproject.org/coprs/eparis/kubernetes-epel-7/repo/epel-7/eparis-kubernetes-epel-7-epel-7.repo -o /etc/yum.repos.d/eparis-kubernetes-epel-7-epel-7.repo # yum install kubernetes -y
配置yy1
# cat /etc/kubernetes/apiserver ### # kubernetes system config # # The following values are used to configure the kubernetes-apiserver # # The address on the local server to listen to. KUBE_API_ADDRESS="10.193.6.35" # The port on the local server to listen on. KUBE_API_PORT="8080" # How the replication controller and scheduler find the apiserver KUBE_MASTER="10.193.6.35:8080" # Comma seperated list of minions MINION_ADDRESSES="10.193.6.36" # Port minions listen on MINION_PORT="10250" # cat /etc/kubernetes/config ### # kubernetes system config # # The following values are used to configure various aspects of all # kubernetes services, including # # kubernetes-apiserver.service # kubernetes-controller-manager.service # kubernetes-kubelet.service # kubernetes-proxy.service # Comma seperated list of nodes in the etcd cluster KUBE_ETCD_SERVERS="http://10.193.6.35:4001" # logging to stderr means we get it in the systemd journal KUBE_LOGTOSTDERR="true" # journal message level, 0 is debug KUBE_LOG_LEVEL=0 # Should this cluster be allowed to run privleged docker containers KUBE_ALLOW_PRIV="true"
啟動(dòng)yy1上相關(guān)服務(wù)
master上需要運(yùn)行etcd,kube-apiserver,kube-controller-manager,kube-scheduler這4個(gè)進(jìn)程。
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES systemctl enable $SERVICES systemctl status $SERVICES done
配置yy2
# cat /etc/kubernetes/kubelet ### # kubernetes kublet (minion) config # The address for the info server to serve on MINION_ADDRESS="10.193.6.36" # The port for the info server to serve on MINION_PORT="10250" # You may leave this blank to use the actual hostname MINION_HOSTNAME="10.193.6.36" # cat /etc/kubernetes/config ### # kubernetes system config # # The following values are used to configure various aspects of all # kubernetes services, including # # kubernetes-apiserver.service # kubernetes-controller-manager.service # kubernetes-kubelet.service # kubernetes-proxy.service # Comma seperated list of nodes in the etcd cluster KUBE_ETCD_SERVERS="http://10.193.6.35:4001" # logging to stderr means we get it in the systemd journal KUBE_LOGTOSTDERR="true" # journal message level, 0 is debug KUBE_LOG_LEVEL=0 # Should this cluster be allowed to run privleged docker containers KUBE_ALLOW_PRIV="true"
修改yy2 kubelet的配置
CentOS7上沒(méi)有docker.socket服務(wù),注釋掉kubelet中對(duì)docker.socket的依賴(lài)。
/usr/lib/systemd/system/kubelet.service
[Unit] Description=Kubernetes Kubelet #After=docker.socket cadvisor.service After=cadvisor.service #Requires=docker.socket cadvisor.service Requires=cadvisor.service
啟動(dòng)yy2上的相關(guān)服務(wù)
minion上需要運(yùn)行kube-proxy,kubelet以及docker。
for SERVICES in kube-proxy kubelet docker; do systemctl restart $SERVICES systemctl enable $SERVICES systemctl status $SERVICES done
創(chuàng)建pod描述文件
創(chuàng)建一個(gè)apache的pod描述文件。
# cat apache.json
{
"id": "apache",
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "apache-1",
"containers": [{
"name": "master",
"image": "fedora/apache",
"ports": [{
"containerPort": 80,
"hostPort": 80
}]
}]
}
},
"labels": {
"name": "apache"
}
}
創(chuàng)建pod
通過(guò)客戶端工具kubecfg提交任務(wù)給apiserver,由scheduler選擇一個(gè)minion部署容。
[root@yy1 ~]# kubecfg -c apache.json create pods I0925 06:43:26.768122 09313 request.go:292] Waiting for completion of /operations/1 ID Image(s) Host Labels Status ---------- ---------- ---------- ---------- ---------- apache fedora/apache / name=apache Waiting [root@yy1 ~]# kubecfg list pods ID Image(s) Host Labels Status ---------- ---------- ---------- ---------- ---------- apache fedora/apache 10.193.6.36/ name=apache Waiting
apache服務(wù)會(huì)自動(dòng)部署到機(jī)器yy2,yy2上的docker會(huì)自動(dòng)下載image,然后啟動(dòng)apache服務(wù)。順利的話,過(guò)一會(huì)兒,apache服務(wù)就會(huì)在yy2上起來(lái)。
[root@yy1 ~]# kubecfg list pods ID Image(s) Host Labels Status ---------- ---------- ---------- ---------- ---------- apache fedora/apache 10.193.6.36/ name=apache Running

可以嘗試訪問(wèn)一下,

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Docker安裝Redis并使用Another?Redis?Desktop?Manager連接的方法
Redis?是一個(gè)使用C語(yǔ)言編寫(xiě)的、開(kāi)源的(遵守?BSD?協(xié)議)、高性能的、支持網(wǎng)絡(luò)、可基于內(nèi)存亦可持久化的日志型、Key-Value的NoSQL數(shù)據(jù)庫(kù),這篇文章主要介紹了Docker安裝Redis并使用Another?Redis?Desktop?Manager連接,需要的朋友可以參考下2022-09-09
Docker下Redis集群(主從+哨兵)安裝配置的實(shí)現(xiàn)步驟
本文主要介紹了Docker下Redis集群(主從+哨兵)安裝配置的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧<BR>2022-07-07
docker容器狀態(tài)轉(zhuǎn)換管理命令實(shí)例詳解
Docker容器只是一個(gè)運(yùn)行于宿主操作系統(tǒng)host?OS上的應(yīng)用進(jìn)程,所以你需要一個(gè)鏡像來(lái)運(yùn)行它,Docker鏡像以進(jìn)程的方式運(yùn)行時(shí)就叫做Docker容器,這篇文章主要給大家介紹了關(guān)于docker容器狀態(tài)轉(zhuǎn)換管理命令的相關(guān)資料,需要的朋友可以參考下2022-05-05
Docker如何解決tomcat容器啟動(dòng)成功,無(wú)法訪問(wèn)的問(wèn)題
這篇文章主要介紹了Docker如何解決tomcat容器啟動(dòng)成功,無(wú)法訪問(wèn)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
Docker容器網(wǎng)絡(luò)端口配置過(guò)程詳解
這篇文章主要介紹了Docker容器網(wǎng)絡(luò)端口配置過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10
docker安裝kong網(wǎng)關(guān)的方法示例
這篇文章主要介紹了docker安裝kong網(wǎng)關(guān)的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-05-05
Docker配置SSL證書(shū)實(shí)現(xiàn)遠(yuǎn)程訪問(wèn)
本文主要介紹了使用OpenSSL生成CA證書(shū)和服務(wù)器證書(shū)并配置Docker以支持SSL連接實(shí)現(xiàn)遠(yuǎn)程訪問(wèn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-01-01

