我是靠谱客的博主 野性溪流,最近开发中收集的这篇文章主要介绍安装kubelet,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1、签发kubelet证书并拷贝

vim kubelet-csr.json
{
    "CN": "k8s-kubelet",
    "hosts": [
    "127.0.0.1",
    "10.4.7.9",
    "10.4.7.12",
    "10.4.7.13",
    "10.4.7.15",
    "10.4.7.16",
    "10.4.7.17",
    "10.4.7.18",
    "10.4.7.19",
    "10.4.7.20"
    ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "ST": "beijing",
            "L": "beijing",
            "O": "k8s",
            "OU": "system"
        }
    ]
}
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=server kubelet-csr.json | cfssl-json -bare kubelet
scp kubelet.pem yanc7-12:/opt/kubernetes/server/bin/certs
scp kubelet-key.pem yanc7-12:/opt/kubernetes/server/bin/certs
scp kubelet.pem yanc7-13:/opt/kubernetes/server/bin/certs
scp kubelet-key.pem yanc7-13:/opt/kubernetes/server/bin/certs

2、创建集群配置和资源

kubectl config set-cluster myk8s 
--certificate-authority=/opt/kubernetes/server/bin/certs/ca.pem 
--embed-certs=true 
--server=https://10.4.7.9:7443 
--kubeconfig=kubelet.kubeconfig

kubectl config set-credentials k8s-node 
--client-certificate=/opt/kubernetes/server/bin/certs/client.pem 
--client-key=/opt/kubernetes/server/bin/certs/client-key.pem 
--embed-certs=true 
--kubeconfig=kubelet.kubeconfig

kubectl config set-context myk8s-context 
--cluster=myk8s 
--user=k8s-node 
--kubeconfig=kubelet.kubeconfig

kubectl config use-context myk8s-context --kubeconfig=kubelet.kubeconfig

vim k8s-node.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: k8s-node
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:node
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: User
  name: k8s-node

kubectl create -f k8s-node.yaml
kubectl get clusterrolebinding k8s-node
kubectl get clusterrolebinding k8s-node -o yaml
scp kubelet.kubeconfig yanc7-13:/opt/kubernetes/server/bin/conf/

3、拉取基础pause镜像并上传到harbor仓库

docker pull kubernetes/pause
docker tag f9d5de079539 harbor.yanc.com/public/pause:latest
docker push harbor.yanc.com/public/pause:latest

4、创建kubelet启动脚本和supervisor配置文件

vim /opt/kubernetes/server/bin/kubelet.sh
#!/bin/sh
./kubelet 
  --anonymous-auth=false 
  --cgroup-driver systemd 
  --cluster-dns 192.168.0.2 
  --cluster-domain cluster.local 
  --runtime-cgroups=/systemd/system.slice 
  --kubelet-cgroups=/systemd/system.slice 
  --fail-swap-on="false" 
  --client-ca-file ./certs/ca.pem 
  --tls-cert-file ./certs/kubelet.pem 
  --tls-private-key-file ./certs/kubelet-key.pem 
  --hostname-override yanc7-12.host.com 
  --image-gc-high-threshold 20 
  --image-gc-low-threshold 10 
  --kubeconfig ./conf/kubelet.kubeconfig 
  --log-dir /data/logs/kubernetes/kube-kubelet 
  --pod-infra-container-image harbor.yanc.com/public/pause:latest 
  --root-dir /data/kubelet

chmod +x /opt/kubernetes/server/bin/kubelet.sh
mkdir -p /data/logs/kubernetes/kube-kubelet /data/kubelet

vim /etc/supervisord.d/kube-kubelet.ini
[program:kube-kubelet-7-12]
command=/opt/kubernetes/server/bin/kubelet.sh     ; the program (relative uses PATH, can take args)
numprocs=1                                        ; number of processes copies to start (def 1)
directory=/opt/kubernetes/server/bin              ; directory to cwd to before exec (def no cwd)
autostart=true                                    ; start at supervisord start (default: true)
autorestart=true                                  ; retstart at unexpected quit (default: true)
startsecs=30                                      ; number of secs prog must stay running (def. 1)
startretries=3                                    ; max # of serial start failures (default 3)
exitcodes=0,2                                     ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT                                   ; signal used to kill process (default TERM)
stopwaitsecs=10                                   ; max num secs to wait b4 SIGKILL (default 10)
user=root                                         ; setuid to this UNIX account to run the program
redirect_stderr=true                              ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/kubernetes/kube-kubelet/kubelet.stdout.log   ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB                      ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=4                          ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB                       ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false                       ; emit events on stdout writes (default false)

supervisorctl update
supervisorctl status

此时kubelet启动有报错:
failed to run Kubelet: misconfiguration: kubelet cgroup driver: “systemd” is different from docker cgroup driver: “cgroupfs”
在这里插入图片描述
docker默认使用的是cgroupfs,kubelet默认使用的是systemd。两者不一致导致启动报错,相关资料可以查阅https://www.cnblogs.com/hongdada/p/9771857.html
修改vim /etc/docker/daemon.json,加入
{
“exec-opts”: [“native.cgroupdriver=systemd”]
}
systemctl daemon-reload
systemctl restart docker

然后再启动kubelet就没问题了
supervisorctl start kube-kubelet-7-12

在这里插入图片描述
kubectl get nodes
在这里插入图片描述
添加角色标签
kubectl label node yanc7-12.host.com node-role.kubernetes.io/master=
kubectl label node yanc7-12.host.com node-role.kubernetes.io/node=
kubectl label node yanc7-13.host.com node-role.kubernetes.io/master=
kubectl label node yanc7-13.host.com node-role.kubernetes.io/node=
在这里插入图片描述

最后

以上就是野性溪流为你收集整理的安装kubelet的全部内容,希望文章能够帮你解决安装kubelet所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部