Docker實踐—CentOS7上部署Kubernetes詳解
Kubernetes架構(gòu)
Kubernetes的整體架構(gòu)如下:
Master為主控節(jié)點,上面運行apiserver,scheduler,controller-manager等組件。Minion相當于工作節(jié)點,上面運行kubelet,proxy,cAdvisor以及最重要的docker等組件。下面來實際部署一下這套集群管理工具。
環(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"
啟動yy1上相關(guān)服務(wù)
master上需要運行etcd,kube-apiserver,kube-controller-manager,kube-scheduler這4個進程。
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上沒有docker.socket服務(wù),注釋掉kubelet中對docker.socket的依賴。
/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
啟動yy2上的相關(guān)服務(wù)
minion上需要運行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)建一個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
通過客戶端工具kubecfg提交任務(wù)給apiserver,由scheduler選擇一個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ù)會自動部署到機器yy2,yy2上的docker會自動下載image,然后啟動apache服務(wù)。順利的話,過一會兒,apache服務(wù)就會在yy2上起來。
[root@yy1 ~]# kubecfg list pods ID Image(s) Host Labels Status ---------- ---------- ---------- ---------- ---------- apache fedora/apache 10.193.6.36/ name=apache Running
可以嘗試訪問一下,
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在云服務(wù)器上基于docker安裝jenkins的實現(xiàn)步驟
本文主要介紹了在云服務(wù)器上基于docker安裝jenkins的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07docker搭建nginx實現(xiàn)負載均衡的示例代碼
本隨著互聯(lián)網(wǎng)應(yīng)用規(guī)模不斷擴大,原有的單一服務(wù)器已經(jīng)無法滿足高并發(fā)和高可用性的要求,本文就來介紹docker搭建nginx實現(xiàn)負載均衡的示例代碼,感興趣的可以了解一下2023-12-12如何解決1130?-?Host?‘172.17.0.1‘?is?not?allowed?to?conne
這篇文章主要介紹了如何解決1130?-?Host?‘172.17.0.1‘?is?not?allowed?to?connect?to?this?MySQL?server的問題,本文給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧2024-08-08解決docker安裝jenkins容器內(nèi)無法訪問外網(wǎng)
這篇文章為大家主要介紹了docker安裝jenkins容器內(nèi)無法訪問外網(wǎng)的問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-11-11在Docker容器中使用iptables時的最小權(quán)限的開啟方法
這篇文章主要介紹了在Docker容器中使用iptables時的最小權(quán)限的開啟方法的相關(guān)資料,需要的朋友可以參考下2017-01-01