您好,登錄后才能下訂單哦!
本文以kubernetes單節(jié)點(diǎn)master安裝為例,為大家分析kubernetes部署單節(jié)點(diǎn)的具體方法。閱讀完整文相信大家kubernetes單節(jié)點(diǎn)部署有了一定的認(rèn)識(shí)。
角色 | 地址 | 安裝組件 |
---|---|---|
master | 192.168.142.220 | kube-apiserver kube-controller-manager kube-scheduler etcd |
node1 | 192.168.142.136 | kubelet kube-proxy docker flannel etcd |
node2 | 192.168.142.132 | kubelet kube-proxy docker flannel etcd |
分隔符前所有操作均在master進(jìn)行,后面均為node節(jié)點(diǎn)
[root@master bin]# pwd
/k8s/kubernetes/server/bin
//node2地址
[root@master bin]# scp -p kubelet kube-proxy root@192.168.142.132:/opt/kubernetes/bin/
//node1地址
[root@master bin]# scp -p kubelet kube-proxy root@192.168.142.136:/opt/kubernetes/bin/
創(chuàng)建bootstrap.kubeconfig(必須品?。。。?/strong>
//指定api入口,指自身即可(必須安裝了apiserver)
[root@master kubernetes]# export KUBE_APISERVER="https://192.168.142.220:6443"
//設(shè)置集群
[root@master kubernetes]# /opt/kubernetes/bin/kubectl config set-cluster kubernetes \
--certificate-authority=/opt/kubernetes/ssl/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER} \
--kubeconfig=/k8s/kubeconfig/bootstrap.kubeconfig
//設(shè)置客戶端認(rèn)證
[root@master kubernetes]# /opt/kubernetes/bin/kubectl config set-credentials kubelet-bootstrap \
--token=${BOOTSTRAP_TOKEN} \
--kubeconfig=/k8s/kubeconfig/bootstrap.kubeconfig
//設(shè)置上下文參數(shù)
[root@master kubernetes]# /opt/kubernetes/bin/kubectl config set-context default \
--cluster=kubernetes \
--user=kubelet-bootstrap \
--kubeconfig=/k8s/kubeconfig/bootstrap.kubeconfig
//設(shè)置默認(rèn)上下文
[root@master kubernetes]# /opt/kubernetes/bin/kubectl config use-context default \
--kubeconfig=/k8s/kubeconfig/bootstrap.kubeconfig
創(chuàng)建kube-proxy kubeconfig文件
//設(shè)置集群
[root@master kubernetes]# /opt/kubernetes/bin/kubectl config set-cluster kubernetes \
--certificate-authority=/opt/etcd/ssl/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER} \
--kubeconfig=/k8s/kubeconfig/kube-proxy.kubeconfig
//設(shè)置客戶端認(rèn)證
[root@master kubernetes]# /opt/kubernetes/bin/kubectl config set-credentials kube-proxy \
--client-certificate=/opt/kubernetes/ssl/kube-proxy.pem \
--client-key=/opt/kubernetes/ssl/kube-proxy-key.pem \
--embed-certs=true \
--kubeconfig=/k8s/kubeconfig/kube-proxy.kubeconfig
//設(shè)置上下文參數(shù)
[root@master kubernetes]# /opt/kubernetes/bin/kubectl config set-context default \
--cluster=kubernetes \
--user=kube-proxy \
--kubeconfig=/k8s/kubeconfig/kube-proxy.kubeconfig
//設(shè)置默認(rèn)上下文
[root@master kubernetes]# /opt/kubernetes/bin/kubectl config use-context default \
--kubeconfig=/k8s/kubeconfig/kube-proxy.kubeconfig
將kubeconfig文件進(jìn)行推送
[root@master kubeconfig]# scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.142.132:/opt/kubernetes/cfg/
[root@master kubeconfig]# scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.142.136:/opt/kubernetes/cfg/
將kubectl寫入環(huán)境變量
[root@master kubeconfig]# echo "export PATH=\$PATH:/opt/kubernetes/bin/" >> /etc/profile
[root@master kubeconfig]# source /etc/profile
(重中之重?。?!沒有基本完蛋)
[root@master kubeconfig]# kubectl create clusterrolebinding kubelet-bootstrap \
--clusterrole=system:node-bootstrapper \
--user=kubelet-bootstrap
指定node節(jié)點(diǎn)IP和DNS為全局變量(不同的node節(jié)點(diǎn)變量需要改變)
不進(jìn)行變量的設(shè)置直接在配置文件進(jìn)行更改也可。
[root@node1 bin]# export NODE_ADDRESS="192.168.142.136"
[root@node1 bin]# export DNS_SERVER_IP="192.168.142.2"
創(chuàng)建kubelet配置文件
[root@node1 ~]# cat <<EOF >/opt/kubernetes/cfg/kubelet
KUBELET_OPTS="--logtostderr=true \\
--v=4 \\
--hostname-override=${NODE_ADDRESS} \\
--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"
EOF
//這是第二個(gè),有兩個(gè)!!記住,有兩個(gè)??!
[root@node1 ~]# cat <<EOF >/opt/kubernetes/cfg/kubelet.config
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: ${NODE_ADDRESS}
port: 10250
readOnlyPort: 10255
cgroupDriver: cgroupfs
clusterDNS:
- ${DNS_SERVER_IP}
clusterDomain: cluster.local.
failSwapOn: false
authentication:
anonymous:
enabled: true
EOF
創(chuàng)建kubelet啟動(dòng)腳本
[root@node1 ~]# cat <<EOF >/usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
After=docker.service
Requires=docker.service
[Service]
EnvironmentFile=/opt/kubernetes/cfg/kubelet
ExecStart=/opt/kubernetes/bin/kubelet \$KUBELET_OPTS
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target
EOF
開啟服務(wù)
[root@node1 ~]# chmod +x /usr/lib/systemd/system/kubelet.service
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl enable kubelet
[root@node1 ~]# systemctl restart kubelet
此時(shí),如果順利則會(huì)在master收到該node節(jié)點(diǎn)發(fā)出的請求加入群集的簽名請求。下面我們要做的就是進(jìn)行請求同意。
[root@master kubeconfig]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-rDZDbQ9_NzqUXKMn2Yn28LVkzEXuITrNqPZ9WrJD5qg 42s kubelet-bootstrap Pending
//“pending” 代表等待狀態(tài)
通過bootstrap角色權(quán)限生成kubelet.kubeconfig
證書文件
[root@master kubeconfig]# kubectl certificate approve node-csr-rDZDbQ9_NzqUXKMn2Yn28LVkzEXuITrNqPZ9WrJD5qg
//此時(shí)node節(jié)點(diǎn)狀態(tài)會(huì)發(fā)生變化
[root@master kubeconfig]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-rDZDbQ9_NzqUXKMn2Yn28LVkzEXuITrNqPZ9WrJD5qg 42s kubelet-bootstrap Approved,Issued
//“Approved” 表示同意請求;“Issued” 表示節(jié)點(diǎn)已發(fā)布
//查看集群情況
[root@master kubeconfig]# kubectl get nodes
NAME STATUS AGE VERSION
192.168.142.136 Ready 49m v1.6.2
以下步驟均在node節(jié)點(diǎn)中進(jìn)行
建立kube-proxy配置文件
[root@node1 ~]# cat <<EOF >/opt/kubernetes/cfg/kube-proxy
KUBE_PROXY_OPTS="--logtostderr=true \\
--v=4 \\
--hostname-override=192.168.142.136 \\
--cluster-cidr=10.0.0.0/24 \\
--proxy-mode=ipvs \\
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig"
EOF
建立kube-proxy啟動(dòng)腳本
[root@node1 ~]# cat <<EOF >/usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Proxy
After=network.target
[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-proxy
ExecStart=/opt/kubernetes/bin/kube-proxy \$KUBE_PROXY_OPTS
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
開啟服務(wù)
[root@node1 ~]# chmod +x /usr/lib/systemd/system/kube-proxy.service
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl enable kube-proxy
[root@node1 ~]# systemctl restart kube-proxy
查看服務(wù)啟動(dòng)狀況
[root@node2 cfg]# netstat -atnp | grep proxy
tcp 0 0 127.0.0.1:10249 0.0.0.0:* LISTEN 50601/kube-proxy
tcp6 0 0 :::10256 :::* LISTEN 50601/kube-proxy
看完這篇文章,你們學(xué)會(huì)kubernetes單節(jié)點(diǎn)安裝的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀! 免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。