您好,登錄后才能下訂單哦!
[root@master01 k8s]# cd /root/k8s/kubernetes/server/bin //進入之前解壓好的軟件命令目錄
[root@master01 bin]# ls
apiextensions-apiserver kube-apiserver.docker_tag kube-proxy
cloud-controller-manager kube-apiserver.tar kube-proxy.docker_tag
cloud-controller-manager.docker_tag kube-controller-manager kube-proxy.tar
cloud-controller-manager.tar kube-controller-manager.docker_tag kube-scheduler
hyperkube kube-controller-manager.tar kube-scheduler.docker_tag
kubeadm kubectl kube-scheduler.tar
kube-apiserver kubelet mounter
[root@master01 bin]# scp kubelet kube-proxy root@192.168.80.13:/opt/kubernetes/bin/ //把 kubelet、 kube-proxy拷貝到node節點上去
root@192.168.80.13's password:
kubelet 100% 168MB 91.4MB/s 00:01
kube-proxy 100% 48MB 71.8MB/s 00:00
[root@master01 bin]# scp kubelet kube-proxy root@192.168.80.14:/opt/kubernetes/bin/
root@192.168.80.14's password:
kubelet 100% 168MB 122.5MB/s 00:01
kube-proxy 100% 48MB 95.2MB/s 00:00
[root@master01 bin]# scp /mnt/node.zip root@192.168.80.13:/root //將宿主機掛載的壓縮文件拷貝到node01節點
root@192.168.80.13's password:
node.zip 100% 1240 4.1KB/s 00:00
[root@node01 ~]# ls
anaconda-ks.cfg flannel.sh flannel-v0.10.0-linux-amd64.tar.gz node.zip README.md
[root@node01 ~]# unzip node.zip //解壓壓縮包
Archive: node.zip
inflating: proxy.sh
inflating: kubelet.sh
master01節點操作
[root@master01 bin]# cd /root/k8s/
[root@master01 k8s]# mkdir kubeconfig //創建配置文件目錄
[root@master01 k8s]# cd kubeconfig
[root@master01 kubeconfig]# cp /mnt/kubeconfig.sh /root/k8s/kubeconfig/ //拷貝腳本到配置文件目錄
[root@master01 kubeconfig]# mv kubeconfig.sh kubeconfig //更名
[root@master01 kubeconfig]# vim kubeconfig //編輯文件
# 創建 TLS Bootstrapping Token
#BOOTSTRAP_TOKEN=$(head -c 16 /dev/urandom | od -An -t x | tr -d ' ')
BOOTSTRAP_TOKEN=0fb61c46f8991b718eb38d27b605b008
cat > token.csv <<EOF
${BOOTSTRAP_TOKEN},kubelet-bootstrap,10001,"system:kubelet-bootstrap"
EOF
//刪除此部分內容
...
:wq
[root@master01 kubeconfig]# cat /opt/kubernetes/cfg/token.csv //查看token文件獲取序列號即可
c37758077defd4033bfe95a071689272,kubelet-bootstrap,10001,"system:kubelet-bootstrap"
[root@master01 kubeconfig]# vim kubeconfig
...
# 設置客戶端認證參數
kubectl config set-credentials kubelet-bootstrap \
--token=c37758077defd4033bfe95a071689272 \ //修改為tokenID 將變量更改為獲取的序列號
--kubeconfig=bootstrap.kubeconfig
...
:wq
[root@master01 kubeconfig]# vim /etc/profile //編輯文件設置環境變量
...
export PATH=$PATH:/opt/kubernetes/bin/
:wq
[root@master01 kubeconfig]# source /etc/profile //重新執行文件
[root@master01 kubeconfig]# kubectl get cs //查看群集狀態,確認群集正常
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health":"true"}
etcd-1 Healthy {"health":"true"}
etcd-2 Healthy {"health":"true"}
[root@master01 kubeconfig]# bash kubeconfig 192.168.80.12 /root/k8s/k8s-cert/ //使用命令生成配置文件
Cluster "kubernetes" set.
User "kubelet-bootstrap" set.
Context "default" created.
Switched to context "default".
Cluster "kubernetes" set.
User "kube-proxy" set.
Context "default" created.
Switched to context "default".
[root@master01 kubeconfig]# ls
bootstrap.kubeconfig kubeconfig kube-proxy.kubeconfig //生成兩個配置文件
[root@master01 kubeconfig]# scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.80.13:/opt/kubernetes/cfg/ //將生成的配置文件拷貝到node節點中
root@192.168.80.13's password:
bootstrap.kubeconfig 100% 2167 1.1MB/s 00:00
kube-proxy.kubeconfig 100% 6269 7.1MB/s 00:00
[root@master01 kubeconfig]# scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.80.14:/opt/kubernetes/cfg/
root@192.168.80.14's password:
bootstrap.kubeconfig 100% 2167 1.6MB/s 00:00
kube-proxy.kubeconfig 100% 6269 4.5MB/s 00:00
[root@master01 kubeconfig]# kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap //創建bootstrap角色賦予權限用于連接apiserver請求簽名(關鍵點)
clusterrolebinding.rbac.authorization.k8s.io/kubelet-bootstrap created
[root@node01 ~]# ls /opt/kubernetes/cfg/ //檢查是否成功拷貝
bootstrap.kubeconfig flanneld kube-proxy.kubeconfig
[root@node01 ~]# bash kubelet.sh 192.168.80.13 //執行腳本文件生成kubelet的配置文件與啟動腳本
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
[root@node01 ~]# systemctl status kubelet.service //查看服務是否啟動
● kubelet.service - Kubernetes Kubelet
Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2020-02-10 14:17:12 CST; 1min 45s ago //成功運行
Main PID: 79678 (kubelet)
Memory: 14.2M
...
[root@master01 kubeconfig]# kubectl get csr //查看是否有node01節點請求申請證書
NAME AGE REQUESTOR CONDITION
node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w 3m16s kubelet-bootstrap Pending
[root@master01 kubeconfig]# kubectl certificate approve node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w //同意自簽node01節點自簽請求
certificatesigningrequest.certificates.k8s.io/node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w approved
[root@master01 kubeconfig]# kubectl get csr //同意后再次查看請求狀態
NAME AGE REQUESTOR CONDITION
node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w 4m40s kubelet-bootstrap Approved,Issued //已經被允許加入群集
[root@master01 kubeconfig]# kubectl get node //查看群集節點,成功加入node01節點
NAME STATUS ROLES AGE VERSION
192.168.80.13 Ready <none> 78s v1.12.3
[root@node01 ~]# bash proxy.sh 192.168.80.13 //執行腳本文件,啟動kube-proxy服務并生成配置文件
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/ systemd/system/kube-proxy.service.
[root@node01 ~]# systemctl status kube-proxy.service //查看服務是否啟動
● kube-proxy.service - Kubernetes Proxy
Loaded: loaded (/usr/lib/systemd/system/kube-proxy.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2020-02-10 14:23:59 CST; 1min 2s ago //成功啟動
Main PID: 80889 (kube-proxy)
...
[root@node01 ~]# scp -r /opt/kubernetes/ root@192.168.80.14:/opt/ //把現成的/opt/kubernetes目錄復制到node02節點進行修改即可
The authenticity of host '192.168.80.14 (192.168.80.14)' can't be established.
ECDSA key fingerprint is SHA256:Ih0NpZxfLb+MOEFW8B+ZsQ5R8Il2Sx8dlNov632cFlo.
ECDSA key fingerprint is MD5:a9:ee:e5:cc:40:c7:9e:24:5b:c1:cd:c1:7b:31:42:0f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.80.14' (ECDSA) to the list of known hosts.
root@192.168.80.14's password:
flanneld 100% 235 139.5KB/s 00:00
bootstrap.kubeconfig 100% 2167 4.6MB/s 00:00
kube-proxy.kubeconfig 100% 6269 14.2MB/s 00:00
kubelet 100% 377 430.7KB/s 00:00
kubelet.config 100% 267 262.3KB/s 00:00
kubelet.kubeconfig 100% 2296 3.3MB/s 00:00
kube-proxy 100% 189 299.2KB/s 00:00
mk-docker-opts.sh 100% 2139 2.3MB/s 00:00
scp: /opt//kubernetes/bin/flanneld: Text file busy
kubelet 100% 168MB 134.1MB/s 00:01
kube-proxy 100% 48MB 129.8MB/s 00:00
kubelet.crt 100% 2185 3.3MB/s 00:00
kubelet.key 100% 1675 2.8MB/s 00:00
kubelet-client-2020-02-10-14-21-18.pem 100% 1273 608.4KB/s 00:00
kubelet-client-current.pem 100% 1273 404.9KB/s 00:00
[root@node01 ~]# scp /usr/lib/systemd/system/{kubelet,kube-proxy}.service root@192.168.80.14:/usr/lib/systemd/system/ //把kubelet,kube-proxy的service文件拷貝到node2中
root@192.168.80.14's password:
kubelet.service 100% 264 350.1KB/s 00:00
kube-proxy.service 100% 231 341.5KB/s 00:00
[root@node02 ~]# cd /opt/kubernetes/ssl/ //進入node01節點拷貝過來的證書目錄
[root@node02 ssl]# rm -rf * //刪除證書,稍后我們在重新申請證書
[root@node02 ssl]# cd ../cfg/ //進入配置文件目錄
[root@node02 cfg]# vim kubelet //修改文件
KUBELET_OPTS="--logtostderr=true \
--v=4 \
--hostname-override=192.168.80.14 \ //修改IP地址
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \
--bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \
--config=/opt/kubernetes/cfg/kubelet.config \
--cert-dir=/opt/kubernetes/ssl \
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
:wq
[root@node02 cfg]# vim kubelet.config //修改配置文件
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 192.168.80.14 //修改IP地址
port: 10250
readOnlyPort: 10255
cgroupDriver: cgroupfs
clusterDNS:
- 10.0.0.2
clusterDomain: cluster.local.
failSwapOn: false
authentication:
anonymous:
enabled: true
:wq
[root@node02 cfg]# vim kube-proxy //修改kube-proxy配置文件
KUBE_PROXY_OPTS="--logtostderr=true \
--v=4 \
--hostname-override=192.168.80.14 \ //修改IP地址
--cluster-cidr=10.0.0.0/24 \
--proxy-mode=ipvs \
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig"
:wq
[root@node02 cfg]# systemctl start kubelet.service //啟動服務
[root@node02 cfg]# systemctl enable kubelet.service //設置開機自啟
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
[root@node02 cfg]# systemctl start kube-proxy.service //啟動服務
[root@node02 cfg]# systemctl enable kube-proxy.service //設置開機自啟
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/ systemd/system/kube-proxy.service.
[root@master01 kubeconfig]# kubectl get csr //查看node節點請求
NAME AGE REQUESTOR CONDITION
node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w 22m kubelet-bootstrap Approved,Issued
node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 4m54s kubelet-bootstrap Pending //等待集群給該節點頒發證書
[root@master01 kubeconfig]# kubectl certificate approve node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 //使用命令授權許可加入群集
certificatesigningrequest.certificates.k8s.io/node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 approved
[root@master01 kubeconfig]# kubectl get csr //再次查看node節點請求
NAME AGE REQUESTOR CONDITION
node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w 23m kubelet-bootstrap Approved,Issued
node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 5m58s kubelet-bootstrap Approved,Issued //成功加入
[root@master01 kubeconfig]# kubectl get node //查看群集中的節點
NAME STATUS ROLES AGE VERSION
192.168.80.13 Ready <none> 20m v1.12.3
192.168.80.14 Ready <none> 76s v1.12.3 //成功加入節點
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。