kubernetes實踐之三十四: Master節點安裝與配置

百聯達發表於2018-05-10
一:簡介
1.kubernetes master節點包含以下元件:kube-apiserver,kube-scheduler和kube-controller-manager。 這三個元件需要部署在同一臺機器上。 同時只能有一個kube-scheduler,kube-controller-manager程式處於工作狀態,如果執行多個,則需要通過選舉產生一個leader.

2.在/etc/kubernetes/ssl目錄下,準備好可能用到的證書檔案。
admin-key.pem admin.pem ca-key.pem ca.pem kube-proxy-key.pem,kube-proxy.pem kubernetes-key.pem kubernetes.pem

3.下載安裝檔案 wget https://storage.googleapis.com/kubernetes-release/release/v1.8.5/kubernetes-server-linux-amd64.tar.gz
tar -xzvf kubernetes-server-linux-amd64.tar.gz
cd kubernetes
tar -xzvf kubernetes-src.tar.gz
複製二進位制檔案到指定目錄
cp -r server/bin/{kube-apiserver,kube-controller-manager,kube-scheduler,kubectl,kube-proxy,kubelet} /usrbin/

二:配置和啟動 kube-apiserver

1.service配置檔案 /usr/lib/systemd/system/kube-apiserver.service

點選(此處)摺疊或開啟

  1. [Unit]
  2. Description=Kubernetes API Service
  3. Documentation=https://github.com/GoogleCloudPlatform/kubernetes
  4. After=network.target
  5. After=etcd.service

  6. [Service]
  7. EnvironmentFile=-/etc/kubernetes/config
  8. EnvironmentFile=-/etc/kubernetes/apiserver
  9. ExecStart=/usr/bin/kube-apiserver \
  10.          $KUBE_LOGTOSTDERR \
  11.          $KUBE_LOG_LEVEL \
  12.          $KUBE_ETCD_SERVERS \
  13.          $KUBE_API_ADDRESS \
  14.          $KUBE_API_PORT \
  15.          $KUBELET_PORT \
  16.          $KUBE_ALLOW_PRIV \
  17.          $KUBE_SERVICE_ADDRESSES \
  18.          $KUBE_ADMISSION_CONTROL \
  19.          $KUBE_API_ARGS
  20. Restart=on-failure
  21. Type=notify
  22. LimitNOFILE=65536

  23. [Install]
  24. WantedBy=multi-user.target
2.配置檔案/etc/kubernetes/config

點選(此處)摺疊或開啟

  1. ###
  2. # kubernetes system config
  3. #
  4. # The following values are used to configure various aspects of all
  5. # kubernetes services, including
  6. #
  7. # kube-apiserver.service
  8. # kube-controller-manager.service
  9. # kube-scheduler.service
  10. # kubelet.service
  11. # kube-proxy.service

  12. # logging to stderr means we get it in the systemd journal
  13. KUBE_LOGTOSTDERR="--logtostderr=true"

  14. # journal message level, 0 is debug
  15. KUBE_LOG_LEVEL="--v=0"

  16. # Should this cluster be allowed to run privileged docker containers
  17. KUBE_ALLOW_PRIV="--allow-privileged=true"

  18. # How the controller-manager, scheduler, and proxy find the apiserver
  19. KUBE_MASTER="--master=http://10.116.137.196:8080"
該配置檔案同時被kube-apiserver、kube-controller-manager、kubescheduler、kubelet、kube-proxy使用。

3.配置檔案 /etc/kubernetes/apiserver

點選(此處)摺疊或開啟

  1. ###
  2. ## kubernetes system config
  3. ##
  4. ## The following values are used to configure the kube-apiserver
  5. ##
  6. #
  7. ## The address on the local server to listen to.
  8. KUBE_API_ADDRESS="--advertise-address=10.116.137.196 --bind-address=10.116.137.196 --insecure-bind-address=10.116.137.196"
  9. #
  10. ## The port on the local server to listen on.
  11. #KUBE_API_PORT="--port=8080"
  12. #
  13. ## Port minions listen on
  14. #KUBELET_PORT="--kubelet-port=10250"
  15. #
  16. ## Comma separated list of nodes in the etcd cluster
  17. KUBE_ETCD_SERVERS="--etcd-servers=https://10.116.137.196:2379,https://10.116.82.28:2379,https://10.116.36.57:2379"
  18. #
  19. ## Address range to use for services
  20. KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
  21. #
  22. ## default admission control policies
  23. KUBE_ADMISSION_CONTROL="--admission-control=ServiceAccount,NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
  24. #
  25. ## Add your own!
  26. KUBE_API_ARGS="--authorization-mode=RBAC --runtime-config=rbac.authorization.k8s.io/v1beta1 --kubelet-https=true --experimental-bootstrap-token-auth --token-auth-file=/etc/kubernetes/token.csv --service-node-port-range=30000-32767 --tls-cert-file=/etc/kubernetes/ssl/kubernetes.pem --tls-private-key-file=/etc/kubernetes/ssl/kubernetes-key.pem --client-ca-file=/etc/kubernetes/ssl/ca.pem --service-account-key-file=/etc/kubernetes/ssl/ca-key.pem --etcd-cafile=/etc/kubernetes/ssl/ca.pem --etcd-certfile=/etc/kubernetes/ssl/kubernetes.pem --etcd-keyfile=/etc/kubernetes/ssl/kubernetes-key.pem --enable-swagger-ui=true --apiserver-count=1 --audit-log-maxage=30 --audit-log-maxbackup=3 --audit-log-maxsize=100 --audit-log-path=/var/lib/audit.log --event-ttl=1h"
a. --authorization-mode=RBAC 指定在安全埠使用 RBAC 授權模式,拒絕未通過授權的請求;

b. kube-scheduler、kube-controller-manager 一般和 kube-apiserver 部署在同一臺機器上,它們使非安全埠和 kube-apiserver通訊;
kubelet、kube-proxy、kubectl 部署在其它 Node 節點上,如果通過安全端?訪問 kube-apiserver,則必須先通過 TLS 證書認證,再通過
RBAC 授權;

c. kube-proxy、kubectl 通過在使?的證書?指定相關的 User、Group來達到通過 RBAC 授權的?的;

d. 如果使用了 kubelet TLS Boostrap 機制,則不能再指定 --kubeletcertificate-authority 、 --kubelet-client-certificate 和 --kubelet-client-key 選項,否則後續 kube-apiserver 校驗 kubelet 證
書時出現 ”x509: certificate signed by unknown authority“ 錯誤;

e. --admission-control 值必須包含 ServiceAccount ;

f. --bind-address 不能為 127.0.0.1 ;

g. runtime-config 配置為 rbac.authorization.k8s.io/v1beta1 ,表示執行時的apiVersion;

h. --service-cluster-ip-range 指定 Service Cluster IP 地址段,該地址段不能路由可達;

i. 預設情況下 kubernetes 物件儲存在 etcd /registry 路徑下,可以通過 --etcd-prefix 引數進行調整;

4.啟動kube-apiserver

systemctl daemon-reload
systemctl enable kube-apiserver
systemctl start kube-apiserver
systemctl status kube-apiserver

三:配置和啟動 kube-controller-manager
1. 服務檔案/usr/lib/systemd/system/kube-controller-manager.service

點選(此處)摺疊或開啟

  1. [Unit]
  2. Description=Kubernetes Controller Manager
  3. Documentation=https://github.com/GoogleCloudPlatform/kubernetes

  4. [Service]
  5. EnvironmentFile=-/etc/kubernetes/config
  6. EnvironmentFile=-/etc/kubernetes/controller-manager
  7. ExecStart=/usr/bin/kube-controller-manager \
  8.          $KUBE_LOGTOSTDERR \
  9.          $KUBE_LOG_LEVEL \
  10.          $KUBE_MASTER \
  11.          $KUBE_CONTROLLER_MANAGER_ARGS
  12. Restart=on-failure
  13. LimitNOFILE=65536
  14. [Install]
  15. WantedBy=multi-user.target
2.配置檔案 /etc/kubernetes/controller-manager

點選(此處)摺疊或開啟

  1. ###
  2. # The following values are used to configure the kubernetes controller-manager
  3. # defaults from config and apiserver should be adequate
  4. # Add your own!
  5. KUBE_CONTROLLER_MANAGER_ARGS="--address=127.0.0.1 --service-cluster-ip-range=10.254.0.0/16 --cluster-name=kubernetes --cluster-signing-cert-file=/etc/kubernetes/ssl/ca.pem --cluster-signing-key-file=/etc/kubernetes/ssl/ca-key.pem --service-account-private-key-file=/etc/kubernetes/ssl/ca-key.pem --root-ca-file=/etc/kubernetes/ssl/ca.pem --leader-elect=true"
a. --service-cluster-ip-range 引數指定 Cluster 中 Service 的CIDR範圍,該?絡在各 Node 間必須路由不可達,必須和 kube-apiserver中的引數一致;

b. --cluster-signing-* 指定的證書和私鑰檔案用來簽名為 TLSBootStrap 建立的證書和私鑰;

c. --root-ca-file 用來對 kube-apiserver 證書進行校驗,指定該引數後,才會在Pod 容器的 ServiceAccount 中放置該 CA 證書檔案;

d. --address 值必須為 127.0.0.1 ,因為當前 kube-apiserver 期望scheduler 和 controller-manager 在同一臺機器

3.啟動 kube-controller-manager
systemctl daemon-reload
systemctl enable kube-controller-manager
systemctl start kube-controller-manager

四:配置和啟動 kube-scheduler
1. 服務檔案/usr/lib/systemd/system/kube-scheduler.service

點選(此處)摺疊或開啟

  1. [Unit]
  2. Description=Kubernetes Scheduler Plugin
  3. Documentation=https://github.com/GoogleCloudPlatform/kubernetes

  4. [Service]
  5. EnvironmentFile=-/etc/kubernetes/config
  6. EnvironmentFile=-/etc/kubernetes/scheduler
  7. ExecStart=/usr/bin/kube-scheduler \
  8.     $KUBE_LOGTOSTDERR \
  9.     $KUBE_LOG_LEVEL \
  10.     $KUBE_MASTER \
  11.     $KUBE_SCHEDULER_ARGS
  12. Restart=on-failure
  13. LimitNOFILE=65536

  14. [Install]
  15. WantedBy=multi-user.target
2. 配置檔案/etc/kubernetes/scheduler

點選(此處)摺疊或開啟

  1. ###
  2. # kubernetes scheduler config
  3. # default config should be adequate
  4. # Add your own!
  5. KUBE_SCHEDULER_ARGS="--leader-elect=true --address=127.0.0.1"
3.啟動 kube-scheduler
systemctl daemon-reload
systemctl enable kube-scheduler
systemctl start kube-scheduler

五:驗證 master 節點功能

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28624388/viewspace-2154257/,如需轉載,請註明出處,否則將追究法律責任。

相關文章