Kubelet組件運行在Node節點上,維持運行中的Pods以及提供kuberntes運行時環境,主要完成如下使命:
1.監視分配給該Node節點的pods
2.掛載pod所須要的volumes
3.下載pod的secret
4.經過docker/rkt來運行pod中的容器
5.週期的執行pod中爲容器定義的liveness探針
6.上報pod的狀態給系統的其餘組件
7.上報Node的狀態 node
kubelet安裝在node節點,咱們的node跟apiserver在一塊兒,這裏安裝在hdss7-21,22上:docker
首先,kubernetes依賴pause,咱們先將此服務上傳到們本身的docker私有倉庫:json
kubernetes中的pause容器主要爲每一個業務容器提供如下功能:api
# docker pull kubernetes/pause
# docker tag f9d5de079539 harbor.od.com/public/pause:latest
# docker push harbor.od.com/public/pause:latest
首先在hdss7-200上申請證書:dom
# vi /opt/certs/kubelet-csr.json
{ "CN": "k8s-kubelet", "hosts": [ "127.0.0.1", "10.4.7.10", "10.4.7.21", "10.4.7.22", "10.4.7.23", "10.4.7.24", "10.4.7.25", "10.4.7.26", "10.4.7.27", "10.4.7.28" ], "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "beijing", "L": "beijing", "O": "od", "OU": "ops" } ] }
申請證書:ide
# cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=server kubelet-csr.json | cfssl-json -bare kubelet
拷貝證書到21,22上:ui
# cd /opt/kubernetes/server/bin/cert/ # scp hdss7-200:/opt/certs/kubelet.pem ./ # scp hdss7-200:/opt/certs/kubelet-key.pem ./
進入到conf目錄執行如下命令:21,22上執行:this
cert]# cd ../conf/
# kubectl config set-cluster myk8s \ --certificate-authority=/opt/kubernetes/server/bin/cert/ca.pem \ --embed-certs=true \ --server=https://10.4.7.10:7443 \ --kubeconfig=kubelet.kubeconfig
# kubectl config set-credentials k8s-node \ --client-certificate=/opt/kubernetes/server/bin/cert/client.pem \ --client-key=/opt/kubernetes/server/bin/cert/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
hdss7-21上執行:PS:由於不論在哪一個節點建立,已經同步到etcd上。spa
conf]# vi 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
檢查k8s-node資源建立狀態:.net
# kubectl get clusterrolebinding k8s-node -o yaml
編輯kubelet啓動腳本:標紅部分第二臺要修改爲對應的主機名
# vi /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 ./cert/ca.pem \ --tls-cert-file ./cert/kubelet.pem \ --tls-private-key-file ./cert/kubelet-key.pem \ --hostname-override hdss7-21.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.od.com/public/pause:latest \ --root-dir /data/kubelet
執行權限:
# chmod u+x /opt/kubernetes/server/bin/kubelet.sh
建立日誌存儲目錄:
# mkdir -p /data/logs/kubernetes/kube-kubelet
編輯supervisord啓動文件:紅色部分自行修改
# vi /etc/supervisord.d/kube-kubelet.ini
[program:kube-kubelet-7-21] 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
給node打tag:
# kubectl label node hdss7-21.host.com node-role.kubernetes.io/master=