您好,登錄后才能下訂單哦!
Kubernetes部署(一):架構及功能說明
Kubernetes部署(二):系統環境初始化
Kubernetes部署(三):CA證書制作
Kubernetes部署(四):ETCD集群部署
Kubernetes部署(五):Haproxy、Keppalived部署
Kubernetes部署(六):Master節點部署
Kubernetes部署(七):Node節點部署
Kubernetes部署(八):Flannel網絡部署
Kubernetes部署(九):CoreDNS、Dashboard、Ingress部署
Kubernetes部署(十):儲存之glusterfs和heketi部署
Kubernetes部署(十一):管理之Helm和Rancher部署
Kubernetes部署(十二):helm部署harbor企業級鏡像倉庫
node只需安裝kubelet服務,所有節點都需要安裝kube-proxy
1.二進制包準備
將軟件包從復制到所有node中去。
[root@node-01 ~]# cd /usr/local/src/kubernetes/server/bin/
[root@node-01 bin]# for n in `seq 204 206`;do scp kubelet 10.31.90.$n:/data/kubernetes/bin/ ;done
[root@node-01 bin]# for n in `seq 201 206`;do scp kube-proxy 10.31.90.$n:/data/kubernetes/bin/ ;done
2.創建角色綁定
[root@node-01 ~]# kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap
clusterrolebinding.rbac.authorization.k8s.io/kubelet-bootstrap created
3.創建 kubelet bootstrapping kubeconfig 文件
設置集群參數
[root@node-01 ~]# kubectl config set-cluster kubernetes \
--certificate-authority=/data/kubernetes/ssl/ca.pem \
--embed-certs=true \
--server=https://10.31.90.200:6443 \
--kubeconfig=bootstrap.kubeconfig
Cluster "kubernetes" set.
設置客戶端認證參數,token要使用之前那個
[root@node-01 ~]# kubectl config set-credentials kubelet-bootstrap \
--token=cf25becebf64e3fffd7f3890a60ac16d \
--kubeconfig=bootstrap.kubeconfig
User "kubelet-bootstrap" set.
設置上下文參數
[root@node-01 ~]# kubectl config set-context default \
--cluster=kubernetes \
--user=kubelet-bootstrap \
--kubeconfig=bootstrap.kubeconfig
Context "default" created.
選擇默認上下文
[root@node-01 ~]# kubectl config use-context default --kubeconfig=bootstrap.kubeconfig
Switched to context "default".
#拷貝到3個node節點
for n in `seq 204 206`;do scp bootstrap.kubeconfig 10.31.90.$n:/data/kubernetes/cfg/;done
部署kubelet(node節點)
[root@node-01 ~]# mkdir -p /etc/cni/net.d
[root@node-01 ~]# cat >>/etc/cni/net.d/10-default.conf<<EOF
{
"name": "flannel",
"type": "flannel",
"delegate": {
"bridge": "docker0",
"isDefaultGateway": true,
"mtu": 1400
}
}
EOF
2.創建kubelet目錄
[root@node-04 ~]# mkdir /var/lib/kubelet
3.創建kubelet服務配置
[root@node-04 ~]# vim /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
WorkingDirectory=/var/lib/kubelet
ExecStart=/data/kubernetes/bin/kubelet \
--address=10.31.90.204 \
--hostname-override=10.31.90.204 \
--pod-infra-container-image=mirrorgooglecontainers/pause-amd64:3.0 \
--experimental-bootstrap-kubeconfig=/data/kubernetes/cfg/bootstrap.kubeconfig \
--kubeconfig=/data/kubernetes/cfg/kubelet.kubeconfig \
--cert-dir=/data/kubernetes/ssl \
--network-plugin=cni \
--cni-conf-dir=/etc/cni/net.d \
--cni-bin-dir=/data/kubernetes/bin/cni \
--cluster-dns=10.1.0.2 \
--cluster-domain=cluster.local. \
--hairpin-mode hairpin-veth \
--allow-privileged=true \
--fail-swap-on=false \
--logtostderr=true \
--v=2 \
--logtostderr=false \
--log-dir=/data/kubernetes/log
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
4.啟動Kubelet
[root@node-04 ~]# systemctl daemon-reload
[root@node-04 ~]# systemctl enable kubelet
[root@node-04 ~]# systemctl start kubelet
5.查看服務狀態
[root@node-04 kubernetes]# systemctl status kubelet
6.查看csr請求
注意是在linux-node1上執行。
[root@node-01 ssl]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-NqH7J1OuDM_jGtQM_VuABiBcAqgDlT_MfJiVS_qWCbg 1m kubelet-bootstrap Pending
node-csr-jy10bYvow5hYQ2sKWfCuBlUNIPit54dhQfzRUd5E6dc 4m kubelet-bootstrap Pending
node-csr-zPPE5g4d1PtbKo-lQWNNC0bbngttC2bdZtwqBBvjrVM 1m kubelet-bootstrap Pending
7.批準kubelet 的 TLS 證書請求
[root@node-01 ~]# kubectl get csr|grep 'Pending' | awk 'NR>0{print $1}'| xargs kubectl certificate approve
執行完畢后,查看節點狀態已經是Ready的狀態了
[root@node-01 ~]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-NqH7J1OuDM_jGtQM_VuABiBcAqgDlT_MfJiVS_qWCbg 1m kubelet-bootstrap Approved,Issued
node-csr-jy10bYvow5hYQ2sKWfCuBlUNIPit54dhQfzRUd5E6dc 5m kubelet-bootstrap Approved,Issued
node-csr-zPPE5g4d1PtbKo-lQWNNC0bbngttC2bdZtwqBBvjrVM 2m kubelet-bootstrap Approved,Issued
kube-proxy master和node節點都安裝
1.配置kube-proxy使用LVS
[root@node-01 ~]# yum install -y ipvsadm ipset conntrack
2.創建 kube-proxy 證書請求
[root@node-01 ssl]# cd /usr/local/src/ssl/
[root@node-01 ssl]# vim kube-proxy-csr.json
{
"CN": "system:kube-proxy",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
3.生成證書
[root@node-01 ssl]# cfssl gencert -ca=/data/kubernetes/ssl/ca.pem \
-ca-key=/data/kubernetes/ssl/ca-key.pem \
-config=/data/kubernetes/ssl/ca-config.json \
-profile=kubernetes kube-proxy-csr.json | cfssljson -bare kube-proxy
4.分發證書到所有node節點
[root@node-01 ssl]# for n in `seq 201 206`;do scp kube-proxy*.pem root@10.31.90.$n:/data/kubernetes/ssl;done
5.創建kube-proxy配置文件
[root@node-01 ~]# kubectl config set-cluster kubernetes \
--certificate-authority=/data/kubernetes/ssl/ca.pem \
--embed-certs=true \
--server=https://10.31.90.200:6443 \
--kubeconfig=kube-proxy.kubeconfig
Cluster "kubernetes" set.
[root@node-01 ~]# kubectl config set-credentials kube-proxy \
--client-certificate=/data/kubernetes/ssl/kube-proxy.pem \
--client-key=/data/kubernetes/ssl/kube-proxy-key.pem \
--embed-certs=true \
--kubeconfig=kube-proxy.kubeconfig
User "kube-proxy" set.
[root@node-01 ~]# kubectl config set-context default \
--cluster=kubernetes \
--user=kube-proxy \
--kubeconfig=kube-proxy.kubeconfig
Context "default" created.
[root@node-01 ~]# kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
Switched to context "default".
6.分發kubeconfig配置文件
[root@node-01 ssl]# for n in `seq 201 206 `;do scp kube-proxy.kubeconfig 10.31.90.$n:/data/kubernetes/cfg/;done
7.創建kube-proxy服務配置
[root@node-04 ~]# mkdir /var/lib/kube-proxy
[root@node-04 ~]# vim /usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
[Service]
WorkingDirectory=/var/lib/kube-proxy
ExecStart=/data/kubernetes/bin/kube-proxy \
--bind-address=10.31.90.204 \
--hostname-override=10.31.90.204 \
--kubeconfig=/data/kubernetes/cfg/kube-proxy.kubeconfig \
--masquerade-all \
--feature-gates=SupportIPVSProxyMode=true \
--proxy-mode=ipvs \
--ipvs-min-sync-period=5s \
--ipvs-sync-period=5s \
--ipvs-scheduler=rr \
--logtostderr=true \
--v=2 \
--logtostderr=false \
--log-dir=/data/kubernetes/log
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
8.啟動Kubernetes Proxy
[root@node-04 ~]# systemctl daemon-reload
[root@node-04 ~]# systemctl enable kube-proxy
[root@node-04 ~]# systemctl start kube-proxy
9.查看服務狀態
查看kube-proxy服務狀態
[root@node-04 scripts]# systemctl status kube-proxy
檢查LVS狀態
[root@node-04 ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.1.0.1:443 rr
-> 10.31.90.201:6443 Masq 1 0 0
如果都安裝了kubelet和proxy服務,使用下面的命令可以檢查狀態:
[root@node-01 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
10.31.90.204 Ready <none> 40m v1.11.5
10.31.90.205 Ready <none> 40m v1.11.5
10.31.90.206 Ready <none> 40m v1.11.5
node-05,node-06節點請自行部署。
后續會陸續更新所有的安裝文檔,如果你覺得我寫的不錯,希望大家多多關注點贊,非常感謝!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。