一、安装部署主控节点控制器,调度器服务

安装部署在21和22上,以21位例

创建启动脚本

[root@hdss7-21 ~]# cd /opt/kubernetes/server/bin
[root@hdss7-21 bin]# vi /opt/kubernetes/server/bin/kube-controller-manager.sh
[root@hdss7-21 bin]# mkdir -p /data/logs/kubernetes/kube-controller-manage
[root@hdss7-21 bin]# chmod +x /opt/kubernetes/server/bin/kube-controller-manager.sh
[root@hdss7-21 bin]# vi /etc/supervisord.d/kube-conntroller-manager.ini
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# cat /opt/kubernetes/server/bin/kube-controller-manager.sh
#!/bin/bash
./kube-controller-manager \
  --cluster-cidr 172.7.0.0/16 \
  --leader-elect true \
  --log-dir /data/logs/kubernetes/kube-controller-manager \
  --master http://127.0.0.1:8080 \
  --service-account-private-key-file ./cert/ca-key.pem \
  --service-cluster-ip-range 192.168.0.0/16 \
  --root-ca-file ./cert/ca.pem \
  --v 2
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# cat /etc/supervisord.d/kube-conntroller-manager.ini
[program:kube-controller-manager-7-21]
command=/opt/kubernetes/server/bin/kube-controller-manager.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-controller-manager/controller.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)
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# vi /opt/kubernetes/server/bin/kube-scheduler.sh
[root@hdss7-21 bin]# cat /opt/kubernetes/server/bin/kube-scheduler.sh
#!/bin/bash
./kube-scheduler \
  --leader-elect  \
  --log-dir /data/logs/kubernetes/kube-scheduler \
  --master http://127.0.0.1:8080 \
  --v 2
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# mkdir -p /data/logs/kubernetes/kube-scheduler
[root@hdss7-21 bin]# chmod +x /opt/kubernetes/server/bin/kube-scheduler.sh
[root@hdss7-21 bin]# vi /etc/supervisord.d/kube-scheduler.ini
[root@hdss7-21 bin]# cat /etc/supervisord.d/kube-scheduler.ini
[program:kube-scheduler-7-21]                   #####注意22的这个地方是需要修改的
command=/opt/kubernetes/server/bin/kube-scheduler.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-scheduler/scheduler.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)
[root@hdss7-21 bin]# ^C

下面就是启动了可能会报错

[root@hdss7-21 bin]# supervisorctl update    当出现下面的报错时候不要慌
error: <class 'xmlrpclib.Fault'>, <Fault 92: "CANT_REREAD: The directory named as part of the path /data/logs/kubernetes/kube-controller-manager/controller.stdout.log does not exist in section 'program:kube-controller-manager-7-22' (file: '/etc/supervisord.d/kube-conntroller-manager.ini')">: file: /usr/lib64/python2.7/xmlrpclib.py line: 794
首先看报错是说你少创建了一个名为/data/logs/kubernetes/kube-controller-manager/的日志文件存放的目录,不管如何先
[root@hdss7-21 bin]# cd /data/logs/kubernetes/kube-controller-manager/   如发现真的不存在那么就创建下再试试
-bash: cd: /data/logs/kubernetes/kube-controller-manager/: No such file or directory
[root@hdss7-21 bin]# mkdir /data/logs/kubernetes/kube-controller-manager/
[root@hdss7-21 bin]# cd /data/logs/kubernetes/kube-controller-manager/
[root@hdss7-21 kube-controller-manager]# ll
total 0
[root@hdss7-21 kube-controller-manager]# cd -
/opt/kubernetes/server/bin
[root@hdss7-21 bin]# /usr/bin/supervisord -c /etc/supervisord.conf     然后加载下若是没有报错那就查看下
[root@hdss7-21 bin]# systemctl startus supervisor       看程序是否运行中,如果有下面的报错
Aug 26 20:01:33 hdss7-21.host.com supervisord[20925]: Error: Another program is already listening on a port that one of our HTTP servers is con...visord.              ##这是告诉你端口被占用了
然后执行下面命令-----执行后程序应该是running了
[root@hdss7-21 bin]# find / -name supervisor.sock
/run/supervisor/supervisor.sock
[root@hdss7-21 bin]# unlink /run/supervisor/supervisor.sock
[root@hdss7-21 bin]# systemctl start supervisord.service
[root@hdss7-21 bin]# systemctl status supervisord.service
程序正常了这时候去查看下组件是否正常
[root@hdss7-21 bin]# supervisorctl status
etcd-server-7-21                 FATAL     Exited too quickly (process log may have details)
kube-apiserver-7-21              FATAL     Exited too quickly (process log may have details)
kube-controller-manager-7-21     FATAL     Exited too quickly (process log may have details)
kube-scheduler-7-21              FATAL     Exited too quickly (process log may have details)
这个时候或许重启下supervisord.service,,会好,如果等一会还不好的话,直接重启下服务就正常了
[root@hdss7-22 ~]# reboot
[root@hdss7-22 ~]# supervisorctl status
etcd-server-7-22                 STARTING  
kube-apiserver-7-22              STARTING  
kube-controller-manager-7-22     STARTING  
kube-scheduler-7-22              STARTING  
[root@hdss7-22 ~]# supervisorctl status
etcd-server-7-22                 RUNNING   pid 9404, uptime 0:00:37
kube-apiserver-7-22              RUNNING   pid 9403, uptime 0:00:37
kube-controller-manager-7-22     RUNNING   pid 9396, uptime 0:00:37
kube-scheduler-7-22              RUNNING   pid 9401, uptime 0:00:37

然后检查下集群的健康状态
检查集群状态
[root@hdss7-21 ~]# ln -s /opt/kubernetes/server/bin/kubectl /usr/bin/kubectl
[root@hdss7-21 ~]# kubectl get cs
NAME                 STATUS    MESSAGE              ERROR
scheduler            Healthy   ok                   
controller-manager   Healthy   ok                   
etcd-1               Healthy   {"health": "true"}   
etcd-0               Healthy   {"health": "true"}   
etcd-2               Healthy   {"health": "true"}  
[root@hdss7-22 ~]# ln -s /opt/kubernetes/server/bin/kubectl /usr/bin/kubectl
[root@hdss7-22 ~]# kubectl get cs
NAME                 STATUS    MESSAGE              ERROR
controller-manager   Healthy   ok                   
scheduler            Healthy   ok                   
etcd-0               Healthy   {"health": "true"}   
etcd-2               Healthy   {"health": "true"}   
etcd-1               Healthy   {"health": "true"}   

二、部署运算节点的kubelet服务

首先去hdss7-200上面去签发证书

[root@hdss7-200 certs]# pwd
/opt/certs
[root@hdss7-200 certs]# vi 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"
        }
    ]
}

[root@hdss7-200 certs]# cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=server kubelet-csr.json |cfssl-json -bare kubelet
2021/08/26 20:31:10 [INFO] generate received request
2021/08/26 20:31:10 [INFO] received CSR
2021/08/26 20:31:10 [INFO] generating key: rsa-2048
2021/08/26 20:31:10 [INFO] encoded CSR
2021/08/26 20:31:10 [INFO] signed certificate with serial number 696748637350679948401932488007150108162485184273
2021/08/26 20:31:10 [WARNING] This certificate lacks a "hosts" field. This makes it unsuitable for
websites. For more information see the Baseline Requirements for the Issuance and Management
of Publicly-Trusted Certificates, v.1.1.6, from the CA/Browser Forum (https://cabforum.org);
specifically, section 10.2.3 ("Information Requirements").
[root@hdss7-200 certs]# ll
total 84
-rw-r--r-- 1 root root 1249 Aug 25 21:03 apiserver.csr
-rw-r--r-- 1 root root  566 Aug 25 21:02 apiserver-csr.json
-rw------- 1 root root 1679 Aug 25 21:03 apiserver-key.pem
-rw-r--r-- 1 root root 1598 Aug 25 21:03 apiserver.pem
-rw-r--r-- 1 root root  836 Aug 25 19:56 ca-config.json
-rw-r--r-- 1 root root  993 Aug 24 21:35 ca.csr
-rw-r--r-- 1 root root  328 Aug 24 21:30 ca-csr.json
-rw------- 1 root root 1679 Aug 24 21:35 ca-key.pem
-rw-r--r-- 1 root root 1346 Aug 24 21:35 ca.pem
-rw-r--r-- 1 root root  993 Aug 25 21:01 client.csr
-rw-r--r-- 1 root root  280 Aug 25 21:00 client-csr.json
-rw------- 1 root root 1675 Aug 25 21:01 client-key.pem
-rw-r--r-- 1 root root 1363 Aug 25 21:01 client.pem
-rw-r--r-- 1 root root 1062 Aug 25 19:56 etcd-peer.csr
-rw-r--r-- 1 root root  363 Aug 25 19:56 etcd-peer-csr.json
-rw------- 1 root root 1679 Aug 25 19:56 etcd-peer-key.pem
-rw-r--r-- 1 root root 1428 Aug 25 19:56 etcd-peer.pem
-rw-r--r-- 1 root root 1115 Aug 26 20:31 kubelet.csr
-rw-r--r-- 1 root root  452 Aug 26 20:29 kubelet-csr.json
-rw------- 1 root root 1675 Aug 26 20:31 kubelet-key.pem
-rw-r--r-- 1 root root 1468 Aug 26 20:31 kubelet.pem
[root@hdss7-200 certs]# docker pull kubernetes/pause
Using default tag: latest
latest: Pulling from kubernetes/pause
4f4fb700ef54: Pull complete 
b9c8ec465f6b: Pull complete 
Digest: sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105
Status: Downloaded newer image for kubernetes/pause:latest
docker.io/kubernetes/pause:latest
[root@hdss7-200 certs]# docker tag f9d5de079539 harbor.od.com/public/pause:latest
[root@hdss7-200 certs]# docker push harbor.od.com/public/pause:latest
The push refers to repository [harbor.od.com/public/pause]
5f70bf18a086: Mounted from public/nginx 
e16a89738269: Pushed 
latest: digest: sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105 size: 938

然后在21和22上进行操作,这里我以21位例

2、接下来就去21上把证书scp过来。。22上同样操作

[root@hdss7-21 cert]# pwd
/opt/kubernetes/server/bin/cert
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/kubelet.pem .
root@hdss7-200's password: 
kubelet.pem                                                                                                        100% 1468   795.0KB/s   00:00    
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/kubelet-key.pem .
root@hdss7-200's password: 
kubelet-key.pem                                                                                                    100% 1675   848.0KB/s   00:00    
[root@hdss7-21 cert]# ll
total 32
-rw------- 1 root root 1679 Jun  1 22:30 apiserver-key.pem
-rw-r--r-- 1 root root 1598 Jun  1 22:30 apiserver.pem
-rw------- 1 root root 1679 Jun  1 22:09 ca-key.pem
-rw-r--r-- 1 root root 1346 Jun  1 22:09 ca.pem
-rw------- 1 root root 1675 Jun  1 22:10 client-key.pem
-rw-r--r-- 1 root root 1363 Jun  1 22:10 client.pem
-rw------- 1 root root 1675 Jun  4 23:23 kubelet-key.pem
-rw-r--r-- 1 root root 1468 Jun  4 23:23 kubelet.pem
3、在7-21还是7-22上创建配置签发证书
[root@hdss7-21 bin]# cd /opt/kubernetes/server/bin/conf/
[root@hdss7-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=kubelet.kubeconfig

conf]# 
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 

conf]#
kubectl config set-context myk8s-context \
--cluster=myk8s \
--user=k8s-node \
--kubeconfig=kubelet.kubeconfig

conf]#
kubectl config use-context myk8s-context --kubeconfig=kubelet.kubeconfig
[root@hdss7-21 conf]# ll
total 8
-rw-r--r-- 1 root root 2224 Jun  1 22:45 audit.yaml
-rw------- 1 root root 1986 Jun  4 23:40 kubelet.kubeconfig
[root@hdss7-21 conf]# ll
total 12
-rw-r--r-- 1 root root 2224 Jun  1 22:45 audit.yaml
-rw------- 1 root root 6195 Jun  4 23:48 kubelet.kubeconfig

[root@hdss7-21 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
[root@hdss7-21 conf]# kubectl create -f k8s-node.yaml 
clusterrolebinding.rbac.authorization.k8s.io/k8s-node created
[root@hdss7-21 conf]# kubectl get clusterrolebinding k8s-node
NAME       AGE
k8s-node   22s
[root@hdss7-21 bin]# 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)
		————————————————
		版权声明:本文为CSDN博主「hakula007」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
		原文链接:https://blog.csdn.net/hakula007/article/details/106414588/

[root@hdss7-21 bin]# supervisorctl update
kube-kubelet-7-21: added process group
[root@hdss7-21 bin]# ^C
[root@hdss7-21 bin]# supervisorctl status
etcd-server-7-21                 RUNNING   pid 23488, uptime 17:26:12
kube-apiserver-7-21              RUNNING   pid 23761, uptime 17:22:24
kube-controller-manager-7-21     RUNNING   pid 25870, uptime 1:59:42
kube-kubelet-7-21                RUNNING   pid 32965, uptime 0:00:34
kube-scheduler-7-21              RUNNING   pid 25860, uptime 1:59:42

然后对22也要进行配置后,进行设置

10、添加标签,,这么能很明显的看到它既做master节点又做node节点
[root@hdss7-21 bin]# kubectl get node
NAME                STATUS   ROLES    AGE     VERSION
hdss7-21.host.com   Ready    <none>   4m24s   v1.15.2
hdss7-22.host.com   Ready    <none>   4m50s   v1.15.2
[root@hdss7-21 bin]# kubectl label node hdss7-21.host.com node-role.kubernetes.io/master=
node/hdss7-21.host.com labeled
[root@hdss7-21 bin]# kubectl get node
NAME                STATUS   ROLES    AGE     VERSION
hdss7-21.host.com   Ready    master   5m49s   v1.15.2
hdss7-22.host.com   Ready    <none>   6m15s   v1.15.2
[root@hdss7-21 bin]# kubectl label node hdss7-21.host.com node-role.kubernetes.io/node=
node/hdss7-21.host.com labeled
[root@hdss7-21 bin]# kubectl get node
NAME                STATUS   ROLES         AGE     VERSION
hdss7-21.host.com   Ready    master,node   6m12s   v1.15.2
hdss7-22.host.com   Ready    <none>        6m38s   v1.15.2
[root@hdss7-21 bin]# kubectl label node hdss7-22.host.com node-role.kubernetes.io/master=
node/hdss7-22.host.com labeled
[root@hdss7-21 bin]# kubectl label node hdss7-22.host.com node-role.kubernetes.io/node=
node/hdss7-22.host.com labeled
[root@hdss7-21 bin]# kubectl get node
NAME                STATUS   ROLES         AGE     VERSION
hdss7-21.host.com   Ready    master,node   6m59s   v1.15.2
hdss7-22.host.com   Ready    master,node   7m25s   v1.15.2

安装部署运算节点服务kube-proxy

集群规划

主机名角色ip
hdss7-21.host.comkube-proxy10.4.7.21
hdss7-22.host.comkube-proxy10.4.7.22

注意:这里部署文档以hdss7-21.host.com主机为例,另一台类似
签发kube-proxy证书

运维主机hdss7-200.host.com上

创建生成证书签名请求(csr)的json配置文件

[root@hdss7-200 certs]# cat kube-proxy-csr.json
{
    "CN": "system:kube-proxy",
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "ST": "beijing",
            "L": "beijing",
            "O": "od",
            "OU": "ops"
        }
    ]
}

[root@hdss7-200 certs]# 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
2021/08/26 22:11:27 [INFO] generate received request
2021/08/26 22:11:27 [INFO] received CSR
2021/08/26 22:11:27 [INFO] generating key: rsa-2048
2021/08/26 22:11:27 [INFO] encoded CSR
2021/08/26 22:11:27 [INFO] signed certificate with serial number 511031509211827152728343928355273045985566954872
2021/08/26 22:11:27 [WARNING] This certificate lacks a "hosts" field. This makes it unsuitable for
websites. For more information see the Baseline Requirements for the Issuance and Management
of Publicly-Trusted Certificates, v.1.1.6, from the CA/Browser Forum (https://cabforum.org);
specifically, section 10.2.3 ("Information Requirements").
[root@hdss7-200 certs]# ll
total 100
-rw-r--r-- 1 root root 1249 Aug 25 21:03 apiserver.csr
-rw-r--r-- 1 root root  566 Aug 25 21:02 apiserver-csr.json
-rw------- 1 root root 1679 Aug 25 21:03 apiserver-key.pem
-rw-r--r-- 1 root root 1598 Aug 25 21:03 apiserver.pem
-rw-r--r-- 1 root root  836 Aug 25 19:56 ca-config.json
-rw-r--r-- 1 root root  993 Aug 24 21:35 ca.csr
-rw-r--r-- 1 root root  328 Aug 24 21:30 ca-csr.json
-rw------- 1 root root 1679 Aug 24 21:35 ca-key.pem
-rw-r--r-- 1 root root 1346 Aug 24 21:35 ca.pem
-rw-r--r-- 1 root root  993 Aug 25 21:01 client.csr
-rw-r--r-- 1 root root  280 Aug 25 21:00 client-csr.json
-rw------- 1 root root 1675 Aug 25 21:01 client-key.pem
-rw-r--r-- 1 root root 1363 Aug 25 21:01 client.pem
-rw-r--r-- 1 root root 1062 Aug 25 19:56 etcd-peer.csr
-rw-r--r-- 1 root root  363 Aug 25 19:56 etcd-peer-csr.json
-rw------- 1 root root 1679 Aug 25 19:56 etcd-peer-key.pem
-rw-r--r-- 1 root root 1428 Aug 25 19:56 etcd-peer.pem
-rw-r--r-- 1 root root 1115 Aug 26 20:31 kubelet.csr
-rw-r--r-- 1 root root  452 Aug 26 20:29 kubelet-csr.json
-rw------- 1 root root 1675 Aug 26 20:31 kubelet-key.pem
-rw-r--r-- 1 root root 1468 Aug 26 20:31 kubelet.pem
-rw-r--r-- 1 root root 1005 Aug 26 22:11 kube-proxy-client.csr
-rw------- 1 root root 1679 Aug 26 22:11 kube-proxy-client-key.pem
-rw-r--r-- 1 root root 1375 Aug 26 22:11 kube-proxy-client.pem
-rw-r--r-- 1 root root  267 Aug 26 22:11 kube-proxy-csr.json

证书签发后去21和22上进行配置

[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/kube-proxy-client.pem .
kube-proxy-client.pem                                     100% 1375   761.6KB/s   00:00    
[root@hdss7-21 cert]# scp hdss7-200:/opt/certs/kube-proxy-client-key.pem .
kube-proxy-client-key.pem                                 100% 1679   797.7KB/s   00:00    
[root@hdss7-21 cert]# cd ..
[root@hdss7-21 bin]# cd conf/
	2、创建服务
	  在操作命令方便复制
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

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

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

conf]#
kubectl config use-context myk8s-context --kubeconfig=kube-proxy.kubeconfig
[root@hdss7-21 conf]# ll
total 24
-rw-r--r-- 1 root root 2223 Aug 25 21:08 audit.yaml
-rw-r--r-- 1 root root  258 Aug 26 20:49 k8s-node.yaml
-rw------- 1 root root 6195 Aug 26 20:47 kubelet.kubeconfig
-rw------- 1 root root 6219 Aug 26 22:15 kube-proxy.kubeconfig
3、修改配置
下面命令方便复制
[root@hdss7-21 conf]# lsmod |grep ip_vs
[root@hdss7-21 ~]# cat 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@hdss7-21 ~]# chmod +x ipvs.sh
[root@hdss7-21 ~]# sh ipvs.sh
[root@hdss7-21 ~]# lsmod |grep ip_vs
ip_vs_wrr              12697  0 
ip_vs_wlc              12519  0 
ip_vs_sh               12688  0 
ip_vs_sed              12519  0 
ip_vs_rr               12600  0 
ip_vs_pe_sip           12740  0 
nf_conntrack_sip       33860  1 ip_vs_pe_sip
ip_vs_nq               12516  0 
ip_vs_lc               12516  0 
ip_vs_lblcr            12922  0 
ip_vs_lblc             12819  0 
ip_vs_ftp              13079  0 
ip_vs_dh               12688  0 
ip_vs                 145497  25 ip_vs_dh,ip_vs_lc,ip_vs_nq,ip_vs_rr,ip_vs_sh,ip_vs_ftp,ip_vs_sed,ip_vs_wlc,ip_vs_wrr,ip_vs_pe_sip,ip_vs_lblcr,ip_vs_lblc
nf_nat                 26787  3 ip_vs_ftp,nf_nat_ipv4,nf_nat_masquerade_ipv4
nf_conntrack          133095  8 ip_vs,nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_netlink,nf_conntrack_sip,nf_conntrack_ipv4
libcrc32c              12644  3 ip_vs,nf_nat,nf_conntrack
[root@hdss7-21 ~]# cat 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@hdss7-21 bin]# cd /opt/kubernetes/server/bin
[root@hdss7-21 bin]# cat /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@hdss7-21 bin]# chmod +x kube-proxy.sh
[root@hdss7-21 bin]# mkdir -p /data/logs/kubernetes/kube-proxy
[root@hdss7-21 bin]# vi /etc/supervisord.d/kube-proxy.ini
[root@hdss7-21 bin]# cat /etc/supervisord.d/kube-proxy.ini
[program:kube-proxy-7-21]        ##注意这里在22上需要修改
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)
[root@hdss7-21 bin]# supervisorctl update
kube-proxy-7-21: added process group
[root@hdss7-21 bin]# supervisorctl status
etcd-server-7-21                 RUNNING   pid 9415, uptime 2:22:24
kube-apiserver-7-21              RUNNING   pid 9425, uptime 2:22:24
kube-controller-manager-7-21     RUNNING   pid 9408, uptime 2:22:24
kube-kubelet-7-21                RUNNING   pid 11202, uptime 1:24:11
kube-proxy-7-21                  STARTING  
kube-scheduler-7-21              RUNNING   pid 9413, uptime 2:22:24
[root@hdss7-21 bin]# supervisorctl status
etcd-server-7-21                 RUNNING   pid 9415, uptime 2:22:49
kube-apiserver-7-21              RUNNING   pid 9425, uptime 2:22:49
kube-controller-manager-7-21     RUNNING   pid 9408, uptime 2:22:49
kube-kubelet-7-21                RUNNING   pid 11202, uptime 1:24:36
kube-proxy-7-21                  RUNNING   pid 31943, uptime 0:00:51
kube-scheduler-7-21              RUNNING   pid 9413, uptime 2:22:49
5、安装LVS,并生成pod
yum install -y ipvsadm
[root@hdss7-21 bin]# yum -y install ipvsadm
[root@hdss7-21 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@hdss7-21 bin]# kubectl get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   192.168.0.1   <none>        443/TCP   3d16h

验证kubernetes集群—在任意一个运算节点上,创建一个资源配置清单

[root@hdss7-21 ~]# cat nginx-ds.yaml 
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: nginx-ds
spec:
  template:
    metadata:
      labels:
        app: nginx-ds
    spec:
      containers:
      - name: my-nginx
        image: harbor.od.com/public/nginx:v1.7.9
        ports:
        - containerPort: 80
然后进行创建
[root@hdss7-21 ~]# kubectl get po     若是一直显示创建中青检查是否登录了harbor仓库
NAME             READY   STATUS              RESTARTS   AGE
nginx-ds-djjjj   0/1     ContainerCreating   0          12s
nginx-ds-qwxxr   0/1     ContainerCreating   0          12s
[root@hdss7-21 ~]# kubectl get po -owide
NAME             READY   STATUS    RESTARTS   AGE     IP           NODE                NOMINATED NODE   READINESS GATES
nginx-ds-djjjj   1/1     Running   0          4m58s   172.7.21.2   hdss7-21.host.com   <none>           <none>
nginx-ds-qwxxr   1/1     Running   0          4m58s   172.7.22.2   hdss7-22.host.com   <none>           <none>

这里可能会遇到报错为

[root@hdss7-21 ~]# kubectl create -f nginx-ds.yaml 
error: unable to recognize "nginx-ds.yaml": no matches for kind "DaemonSet" in version "extensions/v1betal"
这是因为网络不好,在执行下,后创建就可以了
[root@hdss7-21 ~]# 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@hdss7-21 ~]# kubectl create -f nginx-ds.yaml 
daemonset.extensions/nginx-ds created

跨宿主机还是不能通信的

[root@hdss7-21 ~]# curl 172.7.21.2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@hdss7-21 ~]# curl 172.7.22.2
^C
[root@hdss7-21 ~]# 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐