K8S部署05--node部署

满堂花醉三千客,一剑霜寒十四州。这篇文章主要讲述K8S部署05--node部署相关的知识,希望能为你提供帮助。
node节点
192.168.0.211 192.168.0.201
下载node 二进制包

wget https://dl.k8s.io/v1.19.0/kubernetes-node-linux-amd64.tar.gz -O /opt/kubernetes-node-linux-amd64.tar.gz
cd /opt
tar zxvf kubernetes-node-linux-amd64.tar.gz
ln -s /opt/kubernetes/node/bin/kubectl /usr/bin/kubectl
ln -s /opt/kubernetes/node/bin/kubelet /usr/bin/kubelet
ln -s /opt/kubernetes/node/bin/kube-proxy /usr/bin/kube-proxy

kubeconfig配置文件 这个与master节点相同
/etc/kubernetes/kubeconfig
cat > /etc/kubernetes/kubeconfig < < EOF
apiVersion: v1
kind: Config
clusters:
- name: default
cluster:
server: https://192.168.0.250:9443
certificate-authority: /etc/kubernetes/pki/ca.crt
users:
- name: admin
user:
client-certificate: /etc/kubernetes/pki/client.crt
client-key: /etc/kubernetes/pki/client.key
contexts:
- context:
cluster: default
user: admin
name: default
current-context: default
EOF

注意 需要将前文中的证书文件目录复制过来/etc/kubernetes/pki 保证node节点上也有这些证书文件且路径一致。

配置kubelet启动服务
cat > /usr/lib/systemd/system/kubelet.service < < EOF
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/kubernetes/kubernetes
After=docker.target

[Service]
EnvironmentFile=/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet \\$KUBELET_ARGS
Restart=always

[Install]
WantedBy=multi-user.target
EOF

kubelet 参数配置文件
--hostname-override 设定为本机ip 两台机器要注意配置
cat > /etc/kubernetes/kubelet < < EOF
KUBELET_ARGS="--kubeconfig=/etc/kubernetes/kubeconfig --config=/etc/kubernetes/kubelet.config \\
--hostname-override=192.168.0.211 \\
--network-plugin=cni \\
--logtostderr=false --log-dir=/var/log/kubernetes --v=0"
EOF

【K8S部署05--node部署】kubelet 配置config文件
cat > /etc/kubernetes/kubelet.config < < EOF
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 0.0.0.0
port: 10250
cgroupDriver: cgroupfs
clusterDNS: ["169.169.0.100"]
clusterDomain: cluster.local
authentication:
anonymous:
enabled: true
EOF

启动并开机自启动kubelet
注意 swap 一定要关闭 也不要忘记安装docker
systemctl start kubelet& & systemctl enable kubelet



部署 kube-proxy
配置kube-proxy启动服务
cat > /usr/lib/systemd/system/kube-proxy.service < < EOF
[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/kubernetes/kubernetes
After=network.target

[Service]
EnvironmentFile=/etc/kubernetes/proxy
ExecStart=/usr/bin/kube-proxy \\$KUBE_PROXY_ARGS
Restart=always

[Install]
WantedBy=multi-user.target
EOF

kub-proxy 参数配置文件
--hostname-override 设定为本机ip
cat > /etc/kubernetes/proxy < < EOF
KUBE_PROXY_ARGS="--kubeconfig=/etc/kubernetes/kubeconfig \\
--hostname-override=192.168.0.212 \\
--proxy-mode=iptables \\
--logtostderr=false --log-dir=/var/log/kubernetes --v=0"
EOF

启动并开机自启动kube-proxy
systemctl restart kube-proxy& & systemctl enable kube-proxy

在master机器上验证node状态
kubectl --kubeconfig=/etc/kubernetes/kubeconfig get nodes

注意此时 两台node STATUS为NotReady
需要在master上安装网络插件以解决此问题
kubectl --kubeconfig=/etc/kubernetes/kubeconfig apply -f"https://docs.projectcalico.org/manifests/calico.yaml"



注意:
如果kubelet启动不正常,注意观察是否是因为无法拉取pause镜像导致。
可以使用以下方法手动处理。
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.2 k8s.gcr.io/pause:3.2


    推荐阅读