Kubernetes學習系列之簡單叢集安裝與配置
阿新 • • 發佈:2018-11-05
環境配置
CentOS Linux release 7.3.1611 (Core)
etcd-v3.2.6
docker-ce-17.03.2.ce
kubernetes-v1.6.9
192.168.108.128 節點1
192.168.108.129 節點2
192.168.108.130 節點3
Kubernetes下載
https://github.com/kubernetes/kubernetes/releases/download/v1.6.9/kubernetes.tar.gz
安裝配置
先決條件
1.在node節點上必須有可用的docker,docker的安裝請參考官方文件
2.安裝etcd v3,具體安裝可以參考《ETCD叢集安裝配置及簡單應用》
開始安裝
這裡選擇二進位制檔案安裝,下載的kubernetes.tar.gz並不是可執行檔案,而是一系列的指令碼。
解壓已下載的kubernetes.tar.gz
$ tar zxvf kubernetes.tar.gz -C /opt/
$ cd /opt/kubernetes
執行get-kube-binaries.sh下載server和client的可執行檔案
$ ./cluster/get-kube-binaries.sh Kubernetes release: v1.6.9 Server: linux/amd64 (to override, set KUBERNETES_SERVER_ARCH) Client: linux/amd64 (autodetected) Will download kubernetes-server-linux-amd64.tar.gz from https://storage.googleapis.com/kubernetes-release/release/v1.6.9 Will download and extract kubernetes-client-linux-amd64.tar.gz from https://storage.googleapis.com/kubernetes-release/release/v1.6.9 Is this ok? [Y]/n y % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 347M 100 347M 0 0 6110k 0 0:00:58 0:00:58 --:--:-- 10.6M md5sum(kubernetes-server-linux-amd64.tar.gz)=decfd705eb0f32205d9016a41f2262b6 sha1sum(kubernetes-server-linux-amd64.tar.gz)=85f88c723881a092da67230936879909cb7882ac % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 29.0M 100 29.0M 0 0 1910k 0 0:00:15 0:00:15 --:--:-- 2919k md5sum(kubernetes-client-linux-amd64.tar.gz)=ff28d0f1f3384d7594f2a71d2daa89f3 sha1sum(kubernetes-client-linux-amd64.tar.gz)=b941a95770d5f4b5c6784d1918a766480f600930 Extracting /opt/kubernetes/client/kubernetes-client-linux-amd64.tar.gz into /opt/kubernetes/platforms/linux/amd64 Add '/opt/kubernetes/client/bin' to your PATH to use newly-installed binaries.
執行該shell會自動下載kube的server和client可執行檔案,其中客戶端檔案會自動解壓到kubernetes目錄下的client資料夾下,只需將bin新增到PATH下就可以了,這裡也可以不任何處理,因為server的可執行包裡也包含了客戶端命令列工具。服務端可執行檔案下載到了server資料夾,沒有自動解壓,後面會新建立/opt/kube目錄, 然後解壓到當前目錄。
$ cp -au /opt/kubernetes/server/kubernetes-server-linux-amd64.tar.gz /opt/kube $ cd /opt/kube $ tar xzvf /kubernetes-server-linux-amd64.tar.gz
[[email protected] kube]# ll kubernetes/server/bin
總用量 1624384
-rwxr-x--- 1 root root 119891993 8月 24 01:20 cloud-controller-manager
-rwxr-x--- 1 root root 191034128 8月 24 01:20 hyperkube
-rwxr-x--- 1 root root 69883109 8月 24 01:20 kubeadm
-rwxr-x--- 1 root root 55257883 8月 24 01:20 kube-aggregator
-rw-r----- 1 root root 33 8月 24 01:20 kube-aggregator.docker_tag
-rw-r----- 1 root root 56611328 8月 24 01:20 kube-aggregator.tar
-rwxr-x--- 1 root root 149557444 8月 24 01:20 kube-apiserver
-rw-r----- 1 root root 33 8月 24 01:20 kube-apiserver.docker_tag
-rw-r----- 1 root root 150910976 8月 24 01:20 kube-apiserver.tar
-rwxr-x--- 1 root root 131818104 8月 24 01:20 kube-controller-manager
-rw-r----- 1 root root 33 8月 24 01:20 kube-controller-manager.docker_tag
-rw-r----- 1 root root 133171712 8月 24 01:20 kube-controller-manager.tar
-rwxr-x--- 1 root root 70704763 8月 24 01:20 kubectl
-rwxr-x--- 1 root root 68136904 8月 24 01:20 kubefed
-rwxr-x--- 1 root root 138853888 8月 24 01:20 kubelet
-rwxr-x--- 1 root root 64015718 8月 24 01:20 kube-proxy
-rw-r----- 1 root root 33 8月 24 01:20 kube-proxy.docker_tag
-rw-r----- 1 root root 110821888 8月 24 01:20 kube-proxy.tar
-rwxr-x--- 1 root root 75646372 8月 24 01:20 kube-scheduler
-rw-r----- 1 root root 33 8月 24 01:20 kube-scheduler.docker_tag
-rw-r----- 1 root root 76999680 8月 24 01:20 kube-scheduler.tar
配置和啟動服務
構建kubernetes叢集,首先需要在Master節點上啟動kube-apiserver、kube-controller-manager、kube-scheduler服務。然後在每個Node上啟動kubelet、kube-proxy服務。
Master節點服務配置
kube-apiserver.service
vi /usr/lib/systemd/system/kube-apiserver.service
[Unit]
Description=Kube-apiserver Service
After=network.target
[Service]
Type=notify
ExecStart=/opt/kube/kubernetes/server/bin/kube-apiserver \
--admission-control=NamespaceAutoProvision,LimitRanger,SecurityContextDeny \
--apiserver-count=1 \
--cors-allowed-origins=.* \
--enable-garbage-collector=false \
--etcd-servers=http://192.168.108.128:2379 \
--insecure-bind-address=0.0.0.0 \
--insecure-port=8080 \
--log-dir=/opt/kube/log/kube-apiserver \
--logtostderr=false \
--service-cluster-ip-range=192.168.108.0/24 \
--v=5 \
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=default.target
kube-controller-manager.service
$ vi /usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kube-controller-manager Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/kube/kubernetes/server/bin/kube-controller-manager \
--enable-garbage-collector=false \
--logtostderr=false \
--log-dir=/opt/kube/log/kube-controller-manager \
--pod-eviction-timeout=5m0s \
--master=http://0.0.0.0:8080 \
--node-monitor-grace-period=40s \
--terminated-pod-gc-threshold=12500 \
--leader-elect=true \
--v=5 \
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=default.target
kube-scheduler.service
$ vi /usr/lib/systemd/system/kube-scheduler.service
[Unit]
Description=Kube-scheduler Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/kube/kubernetes/server/bin/kube-scheduler \
--log-dir=/opt/kube/log/kube-scheduler \
--logtostderr=false \
--master=http://0.0.0.0:8080 \
--leader-elect=true \
--v=5 \
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=default.target
配置完成後,執行systemctl start命令按順序啟動這3個服務。 systemctl --system daemon-reload
systemctl start kube-apiserver.service
systemctl start kube-controller-manager.service
systemctl start kube-scheduler.service
檢視服務啟動資訊:
systemctl status kube-apiserver.service -l
systemctl status kube-controller-manager.service -l
systemctl status kube-scheduler.service -l
Node服務配置
192.168.108.129
kubelet.service
[Unit]
Description=Kubelet Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/kube/kubernetes/server/bin/kubelet \
--api-servers=http://192.168.108.128:8080 \
--hostname-override=Node-2 \
--image-gc-high-threshold=80 \
--image-gc-low-threshold=50 \
--log-dir=/opt/kube/log/kubelet \
--logtostderr=false \
--pod-infra-container-image=docker.cloudin.com/google_containers/pause-amd64:3.0 \
--system-reserved cpu=2000m,memory=1G \
--v=5 \
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=default.target
kube-proxy.service
$ vi /usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kube-proxy Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/kube/kubernetes/server/bin/kube-proxy \
--log-dir=/opt/kube/log/kube-proxy \
--logtostderr=false \
--master=http://192.168.108.128:8080 \
--v=5 \
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=default.target
192.168.108.130
kubelet.service
$ vi /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubelet Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/kube/kubernetes/server/bin/kubelet \
--api-servers=http://192.168.108.128:8080 \
--hostname-override=Node-3 \
--image-gc-high-threshold=80 \
--image-gc-low-threshold=50 \
--log-dir=/opt/kube/log/kubelet \
--logtostderr=false \
--pod-infra-container-image=docker.cloudin.com/google_containers/pause-amd64:3.0 \
--system-reserved cpu=2000m,memory=1G \
--v=5 \
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=default.target
kube-proxy.service
$ vi /usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kube-proxy Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/kube/kubernetes/server/bin/kube-proxy \
--log-dir=/opt/kube/log/kube-proxy \
--logtostderr=false \
--master=http://192.168.108.128:8080 \
--v=5 \
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=default.target
配置完成後,執行systemctl start命令啟動這2個服務。
systemctl --system daemon-reload
systemctl start kubelet.service systemctl start kube-proxy.service
檢視服務啟動資訊:
systemctl status kubelet.service -l
systemctl status kube-proxy.service -l
客戶端命令
$ cd /opt/kube/kubernetes/server
檢視叢集節點:
$ bin/kubectl get nodes
刪除服務:
$ bin/kubectl delete node $NODENAME
檢視kubernets相關介面:
http://192.168.108.128:8080/