欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

k8s部署-6.node节点组件

程序员文章站 2022-07-13 21:11:59
...

一、传输文件

把主服务器生成的kubeconfig文件复制到从机

scp /opt/kubernetes/ssl/*kubeconfig [email protected]:/opt/kubernetes/cfg/
scp /opt/kubernetes/ssl/*kubeconfig [email protected]:/opt/kubernetes/cfg/

把主服务器上kubelet,kube-proxy传到从机上

scp /tools/kubernetes/kubernetes/server/bin/kubelet [email protected]:/opt/kubernetes/bin/
scp /tools/kubernetes/kubernetes/server/bin/kubelet [email protected]:/opt/kubernetes/bin/

二、master创建用户权限

kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap

三、kubelet

新增kubelet.sh脚本

#!/bin/bash

NODE_ADDRESS=${1:-"192.168.10.61"}
DNS_SERVER_IP=${2:-"10.10.10.2"}

cat <<EOF >/opt/kubernetes/cfg/kubelet

KUBELET_OPTS="--logtostderr=true \\
--v=4 \\
--address=${NODE_ADDRESS} \\
--hostname-override=${NODE_ADDRESS} \\
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \\
--experimental-bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \\
--cert-dir=/opt/kubernetes/ssl \\
--allow-privileged=true \\
--cluster-dns=${DNS_SERVER_IP} \\
--cluster-domain=cluster.local \\
--fail-swap-on=false \\
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"

EOF

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

systemctl daemon-reload
systemctl enable kubelet
systemctl restart kubelet

执行脚本 (当前节点ip,dns地址)

./kubelet.sh 192.168.112.137 10.10.10.2

四、kube-proxy

新增kube-proxy.sh脚本

#!/bin/bash

NODE_ADDRESS=${1:-"192.168.10.61"}

cat <<EOF >/opt/kubernetes/cfg/kube-proxy

KUBE_PROXY_OPTS="--logtostderr=true \
--v=4 \
--hostname-override=${NODE_ADDRESS} \
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig"

EOF

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

systemctl daemon-reload
systemctl enable kube-proxy
systemctl restart kube-proxy

执行脚本 (当前节点ip)

./kube-proxy.sh 192.168.112.137

五、master服务器允许访问

master服务器上

查看node name

kubectl get csr

允许访问

kubectl certificate approve node-csr-qHu1Axkjwf3dNuWexDWwPWAPIRgBLEfj-1-B9VevUl0

查看状态

[[email protected] ~]# kubectl get node
NAME              STATUS   ROLES    AGE     VERSION
192.168.112.137   Ready    <none>   2d16h   v1.18.15
192.168.112.138   Ready    <none>   2d16h   v1.18.15
相关标签: k8s部署