作者:54打工仔i_858 | 来源:互联网 | 2023-09-18 14:06
kubeletb部署
master:
cd /usr/local/src/kubernetes/server/bin/
cp kubelet kube-proxy /opt/kubernetes/bin/
scp kubelet kube-proxy 192.168.56.11:/opt/kubernetes/bin/
scp kubelet kube-proxy 192.168.56.12:/opt/kubernetes/bin/
cd /usr/local/src/ssl
kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap
kubectl config set-cluster kubernetes \
   --certificate-authority=/opt/kubernetes/ssl/ca.pem \
   --embed-certs=true \
   --server=https://192.168.56.10:6443 \
   --kubecOnfig=bootstrap.kubeconfig 
kubectl config set-credentials kubelet-bootstrap \                                     #token 在kube-apiserver启动配置文件内/usr/lib/systemd/system/kube-apiserver配置文件查看token
   --token=ad6d5bb607a186796d8861557df0d17f \
   --kubecOnfig=bootstrap.kubeconfig   
kubectl config set-context default \
   --cluster=kubernetes \
   --user=kubelet-bootstrap \
   --kubecOnfig=bootstrap.kubeconfig
kubectl config use-context default --kubecOnfig=bootstrap.kubeconfig
cp bootstrap.kubeconfig /opt/kubernetes/cfg
scp bootstrap.kubeconfig 192.168.56.12:/opt/kubernetes/cfg
scp bootstrap.kubeconfig 192.168.56.11:/opt/kubernetes/cfg
node节点设置CNI支持,master节点可以不做最好做了吧
mkdir -p /etc/cni/net.d
vim /etc/cni/net.d/10-default.conf
{
        "name": "flannel",
        "type": "flannel",
        "delegate": {
            "bridge": "docker0",
            "isDefaultGateway": true,
            "mtu": 1400
        }
}
mkdir /var/lib/kubelet
vim /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
WorkingDirectory=/var/lib/kubelet
ExecStart=/opt/kubernetes/bin/kubelet \
  --address=192.168.56.12 \
  --hostname-override=192.168.56.11 \
  --pod-infra-container-image=mirrorgooglecontainers/pause-amd64:3.0 \
  --experimental-bootstrap-kubecOnfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \
  --kubecOnfig=/opt/kubernetes/cfg/kubelet.kubeconfig \
  --cert-dir=/opt/kubernetes/ssl \
  --network-plugin=cni \
  --cni-conf-dir=/etc/cni/net.d \
  --cni-bin-dir=/opt/kubernetes/bin/cni \
  --cluster-dns=10.1.0.2 \
  --cluster-domain=cluster.local. \
  --hairpin-mode hairpin-veth \
  --allow-privileged=true \
  --fail-swap-on=false \
  --logtostderr=true \
  --v=2 \
  --logtostderr=false \
  --log-dir=/opt/kubernetes/log
Restart=on-failure
RestartSec=5
systemctl daemon-reload
systemctl enable kubelet
systemctl start kubelet
[root@k8s-master ~]# kubectl get csr
NAME                                                   AGE       REQUESTOR           CONDITION
node-csr-iiYMw6M_Hf3GHAxO9iewAaxEXuBaRQDf1pnXVZ-M-qE   23m       kubelet-bootstrap   Pending
[root@k8s-master ~]# kubectl get node 
NAME            STATUS    ROLES     AGE       VERSION
192.168.56.11   Ready         23h       v1.10.1
192.168.56.12   Ready         23h       v1.10.1
[root@k8s-master ~]# 
kubectl get csr|grep 'Pending' | awk 'NR>0{print $1}'| xargs kubectl certificate approve
[root@k8s-master ~]# kubectl  get node        #我把master节点也加进去了
NAME            STATUS    ROLES     AGE       VERSION
192.168.56.10   Ready         11s       v1.10.1
192.168.56.11   Ready         23h       v1.10.1
192.168.56.12   Ready         23h       v1.10.1
[root@k8s-master ~]#