[program:kube-kubelet-100] command=/opt/kubernetes/server/bin/kubelet-node.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=22 ; 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=false ; redirect proc stderr to stdout (default false) stdout_logfile=/data/logs/kubernetes/kube-kubelet/kubelet.stdout.log ; stdout 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) stderr_logfile=/data/logs/kubernetes/kube-kubelet/kubelet.stderr.log ; stderr log path, NONE for none; default AUTO stderr_logfile_maxbytes=64MB ; max # logfile bytes b4 rotation (default 50MB) stderr_logfile_backups=4 ; # of stderr logfile backups (default 10) stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) stderr_events_enabled=false ; emit events on stderr writes (default false)
启动服务并检查
1 2 3 4 5 6 7 8 9
supervisorctl update supervisorctl status
kubectl label node k8s-node01.boysec.cn node-role.kubernetes.io/master= kubectl label node k8s-node01.boysec.cn node-role.kubernetes.io/node= [root@k8s-node01 conf]# kubectl get node NAME STATUS ROLES AGE VERSION k8s-node01.boysec.cn Ready master,node 3m26s v1.17.4 k8s-node02.boysec.cn Ready master,node 3m37s v1.17.4
cd /opt/kubernetes/server/bin/conf kubectl config use-context myk8s-context --kubeconfig=kube-proxy.kubeconfig
Switched to context "myk8s-context". 创建成功
加载IPVS模块
1 2 3 4 5 6 7 8 9 10 11 12
vim /root/ipvs.sh #!/bin/sh # load LVS IPVS modules # /usr/lib/modules/3.10.0-957.el7.x86_64/kernel/net/netfilter/ipvs/ if [ -d /usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs/ ]; then for module in $(ls /usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs/) do module=${module%%.*} modprobe $module >/dev/null 2>&1 done fi
conf]# ls -l|grep kube-proxy.kubeconfig -rw------- 1 root root 6171 Aug 13 10:32 kube-proxy.kubeconfig chmod +x /opt/kubernetes/server/bin/kube-proxy.sh mkdir -p /data/logs/kubernetes/kube-proxy
创建supervisor配置
vim /etc/supervisord.d/kube-proxy.ini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[program:kube-proxy-100] command=/opt/kubernetes/server/bin/kube-proxy.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=22 ; 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=false ; redirect proc stderr to stdout (default false) stdout_logfile=/data/logs/kubernetes/kube-proxy/proxy.stdout.log ; stdout 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)
启动服务并检查
1 2 3 4 5
supervisorctl update supervisorctl status yum -y install ipvsadm ipvsadm -Ln kubectl get svc
[root@k8s-node01 ~]# kubectl create -f nginx.yaml [root@k8s-node01 ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx 1/1 Running 0 65m 172.7.21.2 k8s-node01.boysec.cn <none> <none>
可能遇到问题
问题:Kubernetes创建Pod失败,无法获取image
1
Failed create pod sandbox: rpc error: code = Unknown desc = failed pulling image "harbor.od.com/public/pause:latest": Error response from daemon: Get http://harbor.od.com/v2/public/pause/manifests/latest: Get http://harbor.od.com:180/service/token?scope=repository%3Apublic%2Fpause%3Apull&service=harbor-registry: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers