角色 | 地址 | 安裝組件 |
---|---|---|
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)
目前創(chuàng)新互聯(lián)已為1000多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、綿陽(yáng)服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、平陸網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。[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寫(xiě)入環(huán)境變量
[root@master kubeconfig]# echo "export PATH=\$PATH:/opt/kubernetes/bin/" >> /etc/profile
[root@master kubeconfig]# source /etc/profile
(重中之重!?。](méi)有基本完蛋)
[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
開(kāi)啟服務(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ā)出的請(qǐng)求加入群集的簽名請(qǐng)求。下面我們要做的就是進(jìn)行請(qǐng)求同意。
[root@master kubeconfig]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-rDZDbQ9_NzqUXKMn2Yn28LVkzEXuITrNqPZ9WrJD5qg 42s kubelet-bootstrap Pending
//“pending” 代表等待狀態(tài)
通過(guò)bootstrap角色權(quán)限生成kubelet.kubeconfig
證書(shū)文件
[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” 表示同意請(qǐng)求;“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
開(kāi)啟服務(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
文章名稱:K8S單master部署四:Kubelet+kube-pro-創(chuàng)新互聯(lián)
分享地址:http://m.rwnh.cn/article40/ddcpho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、企業(yè)網(wǎng)站制作、服務(wù)器托管、網(wǎng)站策劃、App設(shè)計(jì)、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容