一、签发kube-proxy证书(在10.4.7.200主机)
1.创建证书请求json文件
cd /opt/certs/
vim kube-proxy-csr.json
{
"CN": "system:kube-proxy",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "ShangHai",
"L": "ShangHai",
"O": "xy",
"OU": "ops"
}
]
}
2.生成证书文件
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client kube-proxy-csr.json |cfssl-json -bare kube-proxy-client
二、拷贝证书到各个节点(10.4.7.21和10.4.7.22)
scp sx7-200:/opt/certs/kube-proxy-client.pem /opt/kubernetes/server/bin/cert
scp sx7-200:/opt/certs/kube-proxy-client-key.pem /opt/kubernetes/server/bin/cert
创建配置文件(只在一台创建完成后拷贝至另一台)
[root@sx7-21 cert]# cd ../conf/
<1>set-cluster
[root@sx7-21 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=kube-proxy.kubeconfig
<2>set-credentials
[root@sx7-21 conf]# kubectl config set-credentials kube-proxy
--client-certificate=/opt/kubernetes/server/bin/cert/kube-proxy-client.pem
--client-key=/opt/kubernetes/server/bin/cert/kube-proxy-client-key.pem
--embed-certs=true
--kubeconfig=kube-proxy.kubeconfig
<3>set-context
[root@sx7-21 conf]# kubectl config set-context myk8s-context
--cluster=myk8s
--user=kube-proxy
--kubeconfig=kube-proxy.kubeconfig
<4>use-context
[root@sx7-21 conf]# kubectl config use-context myk8s-context --kubeconfig=kube-proxy.kubeconfig
<5>拷贝至10.4.7.22主机的/opt/kubernetes/server/bin/conf目录下
[root@sx7-22 conf]# scp sx7-21:/opt/kubernetes/server/bin/conf/kube-proxy.kubeconfig .
三、创建启动脚本(10.4.7.21和10.4.7.22),以7.21为例
1.加载ipvs模块
[root@sx7-21 ~]# vim ipvs.sh
#!/bin/bash ipvs_mods_dir="/usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs" for i in $(ls $ipvs_mods_dir|grep -o "^[^.]*") do /sbin/modinfo -F filename $i &>/dev/null if [ $? -eq 0 ];then /sbin/modprobe $i fi done
[root@sx7-21 ~]# chmod +x ipvs.sh
[root@sx7-21 ~]# ./ipvs.sh
[root@sx7-21 ~]# lsmod | grep ip_vs
2.创建启动脚本
[root@sx7-21 ~]# vi /opt/kubernetes/server/bin/kube-proxy.sh
#!/bin/sh
./kube-proxy
--cluster-cidr 172.7.0.0/16
--hostname-override hdss7-21.host.com
--proxy-mode=ipvs
--ipvs-scheduler=nq
--kubeconfig ./conf/kube-proxy.kubeconfig
修改权限,创建目录
[root@sx7-21 ~]# chmod +x /opt/kubernetes/server/bin/kube-proxy.sh
[root@sx7-21 ~]# mkdir -p /data/logs/kubernetes/kube-proxy
3.创建supervisor配置
[root@sx7-21 ~]# vi /etc/supervisord.d/kube-proxy.ini // 另一台修改红色的字体
[program:kube-proxy-7-21] 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=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-proxy/proxy.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
四、安装LVS(10.4.7.21和10.4.7.22)
yum install -y ipvsadm