部署node节点组件

Posted jasonboren

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了部署node节点组件相关的知识,希望对你有一定的参考价值。

部署node节点组件

mv kubelet kube-proxy /opt/kubernetes/bin
chmod +x /opt/kubernetes/bin/* && chmod +x *.sh
./kubelet.sh 172.16.163.130 10.10.10.2
./proxy.sh 172.16.163.130

kubelet.sh

[root@node1 ~]# cat kubelet.sh 
#!/bin/bash

NODE_ADDRESS=${1:-"192.168.1.196"}
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

kubelet.service

[root@node1 ~]# cat  /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

proxy.sh

[root@node1 ~]# cat proxy.sh 
#!/bin/bash

NODE_ADDRESS=${1:-"192.168.1.200"}

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

kube-proxy.service

[root@node1 ~]# cat /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

执行完成之后需要添加角色权限

kubectl create clusterrolebinding kubelet-bootstrap   --clusterrole=system:node-bootstrapper   --user=kubelet-bootstrap
  
  clusterrolebinding.rbac.authorization.k8s.io/kubelet-bootstrap created

查看csr列表

  kubectl get csr
[root@master ~]# kubectl get csr
NAME                                                   AGE     REQUESTOR           CONDITION
node-csr-81F5uBehyEyLWco5qavBsxc1GzFcZk3aFM3XW5rT3mw   5m52s   kubelet-bootstrap   Pending
node-csr-Ed0kbFhc_q7qx14H3QpqLIUs0uKo036O2SnFpIheM18   6m56s   kubelet-bootstrap   Pending

授权

[root@master ~]# kubectl  certificate approve node-csr-81F5uBehyEyLWco5qavBsxc1GzFcZk3aFM3XW5rT3mw node-csr-Ed0kbFhc_q7qx14H3QpqLIUs0uKo036O2SnFpIheM18
certificatesigningrequest.certificates.k8s.io/node-csr-81F5uBehyEyLWco5qavBsxc1GzFcZk3aFM3XW5rT3mw approved
certificatesigningrequest.certificates.k8s.io/node-csr-Ed0kbFhc_q7qx14H3QpqLIUs0uKo036O2SnFpIheM18 approved

查看node集群节点信息

[root@master ~]# kubectl get nodes
NAME             STATUS   ROLES    AGE   VERSION
172.16.163.129   Ready    <none>   18s   v1.9.0
172.16.163.130   Ready    <none>   19s   v1.9.0

以上是关于部署node节点组件的主要内容,如果未能解决你的问题,请参考以下文章

Kubernetes节点服务搭建————二进制部署|单master节点配置(master组件部署|node组件部署)

Kubernetes节点服务搭建————二进制部署|单master节点配置(master组件部署|node组件部署)

Kubernetes节点服务搭建————二进制部署|单master节点配置(master组件部署|node组件部署)

三 node节点部署k8s组件

kubernetes架构-组件交互篇

08-部署node节点