1. 我是皮皮虾首页
  2. 网站部署

k8s安装Node节点之部署kube-proxy(四)

部署机器

  • hdss7-21
  • hdss7-22

创建生成证书csr的json配置文件
在hdss7-200的主机上操作

注意:下面的system:kube-proxy不能修改,这个是k8s系统角色,修改后,你会得到这个错误:

E0921 18:21:36.919145 1137 reflector.go:125] k8s.io/client-go/informers/factory.go:133: Failed to list *v1.Service: services is forbidden: User “kube-proxy” cannot list resource “services” in API group “” at the cluster scope
E0921 18:21:36.920774 1137 reflector.go:125] k8s.io/client-go/informers/factory.go:133: Failed to list *v1.Endpoints: endpoints is forbidden: User “kube-proxy” cannot list resource “endpoints” in API group “” at the cluster scope

cd /opt/certs
cat > kube-proxy-csr.json <<'eof'
{
    "CN": "system:kube-proxy",
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "ST": "GuangZhou",
            "L": "GuangZhou",
            "O": "k8s",
            "OU": "yw"
        }
    ]
}
eof

3、生成Kube-proxy的client证书

[root@hdss7-200 certs]# cd /opt/certs
[root@hdss7-200 certs]# cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client kube-proxy-csr.json |cfssljson -bare kube-proxy-client
[root@hdss7-200 certs]# ll kube-proxy-c*
-rw-r--r--. 1 root root 1009 9月  20 22:37 kube-proxy-client.csr
-rw-------. 1 root root 1675 9月  20 22:37 kube-proxy-client-key.pem
-rw-r--r--. 1 root root 1387 9月  20 22:37 kube-proxy-client.pem
-rw-r--r--. 1 root root  271 9月  20 22:37 kube-proxy-csr.json

4、拷贝证书

scp /opt/certs/kube-proxy-client.pem hdss7-21:/opt/kubernetes/server/bin/certs
scp /opt/certs/kube-proxy-client-key.pem hdss7-21:/opt/kubernetes/server/bin/certs
scp /opt/certs/kube-proxy-client.pem hdss7-22:/opt/kubernetes/server/bin/certs
scp /opt/certs/kube-proxy-client-key.pem hdss7-22:/opt/kubernetes/server/bin/certs

5、创建配置
在hdss7-21.host.com上操作,不需要在hdss7-22上操作,只需要拷贝proxy.kubeconfig文件到22机器上即可
5.1 set-cluster

cd /opt/kubernetes/server/bin/conf
kubectl config set-cluster myk8s \
--certificate-authority=/opt/kubernetes/server/bin/certs/ca.pem \
--embed-certs=true \
--server=https://10.4.7.10:7443 \
--kubeconfig=kube-proxy.kubeconfig

5.2 set-credentials

kubectl config set-credentials kube-proxy \
  --client-certificate=/opt/kubernetes/server/bin/certs/kube-proxy-client.pem \
  --client-key=/opt/kubernetes/server/bin/certs/kube-proxy-client-key.pem \
  --embed-certs=true \
  --kubeconfig=kube-proxy.kubeconfig

5.3 set-context

kubectl config set-context myk8s-context \
--cluster=myk8s \
--user=kube-proxy \
--kubeconfig=kube-proxy.kubeconfig

5.4 use-context

kubectl config use-context myk8s-context --kubeconfig=kube-proxy.kubeconfig

6、拷贝配置到hdss7-22

scp kube-proxy.kubeconfig hdss7-22:/opt/kubernetes/server/bin/conf/kube-proxy.kubeconfig

7、加载ipvs模块
在hdss7-21.host.com,hdss7-22.host.com上操作,以hdss7-21操作为例

lsmod |grep ip_vs
cat > /root/ipvs.sh <<'eof'
#!/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
eof
chmod +x /root/ipvs.sh 
sh /root/ipvs.sh 
lsmod |grep ip_vs

8、创建启动脚本
在hdss7-22需要修改的地方:–hostname-override hdss7-21.host.com

cat > /opt/kubernetes/server/bin/kube-proxy.sh <<'eof'
#!/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
eof
chmod +x /opt/kubernetes/server/bin/kube-proxy.sh
mkdir -p /data/logs/kubernetes/kube-proxy

9、创建supervisor配置
在hdss7-22需要修改的地方:[program:kube-proxy-7-21]

cat > /etc/supervisord.d/kube-proxy.ini <<'eof'
[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)
eof

10、启动服务并检查

[root@hdss-7-22 bin]# supervisorctl update
[root@hdss-7-22 bin]# supervisorctl status
etcd-server-7-22                 RUNNING   pid 1141, uptime 0:35:32
kube-apiserver-7-22              RUNNING   pid 1120, uptime 0:35:32
kube-controller-manager-7-22     RUNNING   pid 1131, uptime 0:35:32
kube-kubelet-7-22                RUNNING   pid 1119, uptime 0:35:32
kube-proxy-7-22                  RUNNING   pid 3175, uptime 0:13:23
kube-scheduler-7-22              RUNNING   pid 1148, uptime 0:35:32

[root@hdss-7-22 bin]# yum install ipvsadm -y
[root@hdss-7-22 bin]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.0.1:443 nq
  -> 10.4.7.21:6443               Masq    1      0          0         
  -> 10.4.7.22:6443               Masq    1      0          0         
[root@hdss-7-22 bin]# kubectl get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   192.168.0.1   <none>        443/TCP   19h
[root@hdss-7-22 bin]# 

原创文章,作者:站长,如若转载,请注明出处:https://wsppx.cn/1754/%e7%bd%91%e7%ab%99%e9%83%a8%e7%bd%b2/

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注