一、安装部署主控节点服务
部署master节点服务
部署etcd集群
集群规则:
主机名 | 角色 | IP |
---|
hdss7-12.host.com | etcd lead | 10.4.7.12 | hdss7-21.host.com | etcd follow | 10.4.7.21 | hdss7-22.host.com | etcd follow | 10.4.7.22 |
注意:这里以12为例子,其他两台参考安装
1、创建基于根证书的config配置文件
首先在hdss7-200上做出证书
1、下面就是改配置etcd了需要在hdss7-200进行操作
cat > /opt/certs/ca-config.json <<EOF
{
"signing": {
"default": {
"expiry": "175200h"
},
"profiles": {
"server": {
"expiry": "175200h",
"usages": [
"signing",
"key encipherment",
"server auth"
]
},
"client": {
"expiry": "175200h",
"usages": [
"signing",
"key encipherment",
"client auth"
]
},
"peer": {
"expiry": "175200h",
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
]
}
}
}
}
EOF
cat > /opt/certs/etcd-peer-csr.json <<EOF
{
"CN": "k8s-etcd",
"hosts": [
"10.4.7.11",
"10.4.7.12",
"10.4.7.21",
"10.4.7.22"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "beijing",
"L": "beijing",
"O": "od",
"OU": "ops"
}
]
}
EOF
2、创建证书。并查看证书是否创建好了
cd /opt/certs/
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=peer etcd-peer-csr.json |cfssl-json -bare etcd-peer
ll
有下面的内容说明证书已经创建好了
[root@hdss7-200 certs]
total 36
-rw-r--r--. 1 root root 836 May 29 23:15 ca-config.json
-rw-r--r--. 1 root root 993 May 29 17:45 ca.csr
-rw-r--r--. 1 root root 328 May 29 17:32 ca-csr.json
-rw-------. 1 root root 1679 May 29 17:45 ca-key.pem
-rw-r--r--. 1 root root 1346 May 29 17:45 ca.pem
-rw-r--r--. 1 root root 1062 May 29 23:15 etcd-peer.csr
-rw-r--r--. 1 root root 363 May 29 23:15 etcd-peer-csr.json
-rw-------. 1 root root 1679 May 29 23:15 etcd-peer-key.pem
-rw-r--r--. 1 root root 1428 May 29 23:15 etcd-peer.pe
2、创建etcd–分别在三台机上进行创建
首先在12上进行创建
[root@hdss7-12 ~]
[root@hdss7-12 ~]
[root@hdss7-12 src]
total 0
[root@hdss7-12 src]
[root@hdss7-12 src]
rz waiting to receive.
[root@hdss7-12 src]
total 9620
-rw-r--r-- 1 root root 9850227 May 25 22:31 etcd-v3.1.20-linux-amd64.tar.gz
[root@hdss7-12 src]
[root@hdss7-12 opt]
[root@hdss7-12 opt]
[root@hdss7-12 opt]
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
[root@hdss7-12 certs]
[root@hdss7-12 certs]
[root@hdss7-12 certs]
[root@hdss7-12 certs]
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
./etcd --name etcd-server-7-12 \
--data-dir /data/etcd/etcd-server \
--listen-peer-urls https://10.4.7.12:2380 \
--listen-client-urls https://10.4.7.12:2379,http://127.0.0.1:2379 \
--quota-backend-bytes 8000000000 \
--initial-advertise-peer-urls https://10.4.7.12:2380 \
--advertise-client-urls https://10.4.7.12:2379,http://127.0.0.1:2379 \
--initial-cluster etcd-server-7-12=https://10.4.7.12:2380,etcd-server-7-21=https://10.4.7.21:2380,etcd-server-7-22=https://10.4.7.22:2380 \
--ca-file ./certs/ca.pem \
--cert-file ./certs/etcd-peer.pem \
--key-file ./certs/etcd-peer-key.pem \
--client-cert-auth \
--trusted-ca-file ./certs/ca.pem \
--peer-ca-file ./certs/ca.pem \
--peer-cert-file ./certs/etcd-peer.pem \
--peer-key-file ./certs/etcd-peer-key.pem \
--peer-client-cert-auth \
--peer-trusted-ca-file ./certs/ca.pem \
--log-output stdout
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@hdss7-12 etcd]
[root@hdss7-12 etcd]
[program:etcd-server-7-12] ; 显示的程序名,类型my.cnf,可以有多个
command=/opt/etcd/etcd-server-startup.sh
numprocs=1 ; 启动进程数 (def 1)
directory=/opt/etcd ; 启动命令前切换的目录 (def no cwd)
autostart=true ; 是否自启 (default: true)
autorestart=true ; 是否自动重启 (default: true)
startsecs=30 ; 服务运行多久判断为成功(def. 1)
startretries=3 ; 启动重试次数 (default 3)
exitcodes=0,2 ; 退出状态码 (default 0,2)
stopsignal=QUIT ; 退出信号 (default TERM)
stopwaitsecs=10 ; 退出延迟时间 (default 10)
user=etcd ; 运行用户
redirect_stderr=true ; 是否重定向错误输出到标准输出(def false)
stdout_logfile=/data/logs/etcd-server/etcd.stdout.log
stdout_logfile_maxbytes=64MB ; 日志文件大小 (default 50MB)
stdout_logfile_backups=4 ; 日志文件滚动个数 (default 10)
stdout_capture_maxbytes=1MB ; 设定capture管道的大小(default 0)
stdout_events_enabled=false ; 子进程还有子进程,需要添加这个参数,避免产生孤儿进程
[root@hdss7-12 etcd]
etcd-server-7-12: added process group
[root@hdss7-12 etcd]
etcd-server-7-12 STARTING
[root@hdss7-12 etcd]
etcd-server-7-12 STARTING
[root@hdss7-12 etcd]
2021-08-25 20:11:36.670777 I | rafthttp: started HTTP pipelining with peer 5a0ef2a004fc4349
2021-08-25 20:11:36.671441 I | rafthttp: started streaming with peer 5a0ef2a004fc4349 (writer)
2021-08-25 20:11:36.672325 I | rafthttp: started peer 5a0ef2a004fc4349
2021-08-25 20:11:36.672351 I | rafthttp: added peer 5a0ef2a004fc4349
2021-08-25 20:11:36.672364 I | etcdserver: starting server... [version: 3.1.20, cluster version: to_be_decided]
........
[root@hdss7-12 etcd]
etcd-server-7-12 RUNNING pid 25178, uptime 0:00:59
[root@hdss7-12 etcd]
tcp 0 0 10.4.7.12:2379 0.0.0.0:* LISTEN 25179/./etcd
tcp 0 0 127.0.0.1:2379 0.0.0.0:* LISTEN 25179/./etcd
tcp 0 0 10.4.7.12:2380 0.0.0.0:* LISTEN 25179/./etcd
在做一个在21上做etcd
[root@hdss7-21 ~]
[root@hdss7-21 ~]
[root@hdss7-21 ~]
[root@hdss7-21 src]
/opt/src
[root@hdss7-21 src]
[root@hdss7-21 src]
[root@hdss7-21 src]
[root@hdss7-21 opt]
[root@hdss7-21 opt]
[root@hdss7-21 opt]
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
[root@hdss7-21 certs]
[root@hdss7-21 certs]
etcd-peer.pem 100% 1428 1.2MB/s 00:00
[root@hdss7-21 certs]
etcd-peer-key.pem 100% 1679 515.6KB/s 00:00
[root@hdss7-21 certs]
total 12
-rw-r--r-- 1 root root 1346 Aug 25 20:26 ca.pem
-rw------- 1 root root 1679 Aug 25 20:27 etcd-peer-key.pem
-rw-r--r-- 1 root root 1428 Aug 25 20:27 etcd-peer.pem
[root@hdss7-21 certs]
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl
Trying other mirror.
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Package epel-release-7-13.noarch already installed and latest version
Nothing to do
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
etcd-server-7-21: added process group
[root@hdss7-21 etcd]
etcd-server-7-21 STARTING
[root@hdss7-21 etcd]
[root@hdss7-21 etcd]
etcd-server-7-21 RUNNING pid 28560, uptime 0:00:37
等三台等running后去检查先集群的健康情况,在任意一台都行
[root@hdss7-22 etcd]
tcp 0 0 10.4.7.22:2379 0.0.0.0:* LISTEN 26655/./etcd
tcp 0 0 127.0.0.1:2379 0.0.0.0:* LISTEN 26655/./etcd
tcp 0 0 10.4.7.22:2380 0.0.0.0:* LISTEN 26655/./etcd
[root@hdss7-22 etcd]
member 988139385f78284 is healthy: got healthy result from http://127.0.0.1:2379
member 5a0ef2a004fc4349 is healthy: got healthy result from http://127.0.0.1:2379
member f4a0cb0a765574a8 is healthy: got healthy result from http://127.0.0.1:2379
cluster is healthy
[root@hdss7-22 etcd]
988139385f78284: name=etcd-server-7-22 peerURLs=https://10.4.7.22:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.22:2379 isLeader=false
5a0ef2a004fc4349: name=etcd-server-7-21 peerURLs=https://10.4.7.21:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.21:2379 isLeader=false
f4a0cb0a765574a8: name=etcd-server-7-12 peerURLs=https://10.4.7.12:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.12:2379 isLeader=true
二、部署kube-apiserver
集群规划
主机名 | 角色 | ip |
---|
hdss7-21.host.com | kube-apiserver | 10.4.7.21 | hdss7-22.host.com | kube-apiserver | 10.4.7.22 | hdss7-11.host.com | 4层负载均衡 | 10.4.7.11 | hdss7-12.host.com | 4层负载均衡 | 10.4.7.12 |
注意:这里的10.4.7.11和10.4.7.12使用nginx做4层负载均衡,用keepalived跑一个vip:10.4.7.10 代理两个kube-apiserver,实现高可用 这里部署文档以hdss7-21.host.com 主机为例,另外的运算节点参考类似
下载软件解压,做软连接
下载地址:: 需要安装在10.4.7.21和10.4.7.22上 https://github.com/kubernetes/kubernetes https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.15.md#downloads-for-v11512
[root@hdss7-21 etcd]
[root@hdss7-21 src]
total 9620
-rw-r--r-- 1 root root 9850227 Aug 25 20:21 etcd-v3.1.20-linux-amd64.tar.gz
[root@hdss7-21 src]
rz waiting to receive.
[root@hdss7-21 src]
[root@hdss7-21 src]
[root@hdss7-21 opt]
[root@hdss7-21 opt]
[root@hdss7-21 opt]
total 20
drwx--x--x 4 root root 4096 Aug 24 22:01 containerd
lrwxrwxrwx 1 root root 18 Aug 25 20:22 etcd -> /opt/etcd-v3.1.20/
drwxr-xr-x 4 etcd etcd 4096 Aug 25 20:29 etcd-v3.1.20
lrwxrwxrwx 1 root root 24 Aug 25 20:56 kubernetes -> /opt/kubernetes-v1.15.2/
drwxr-xr-x 4 root root 4096 Aug 5 2019 kubernetes-v1.15.2
drwxr-xr-x. 2 root root 4096 Oct 31 2018 rh
drwxr-xr-x 2 root root 4096 Aug 25 20:53 src
[root@hdss7-21 opt]
[root@hdss7-21 kubernetes]
total 27192
drwxr-xr-x 2 root root 4096 Aug 5 2019 addons
-rw-r--r-- 1 root root 26625140 Aug 5 2019 kubernetes-src.tar.gz
-rw-r--r-- 1 root root 1205293 Aug 5 2019 LICENSES
drwxr-xr-x 3 root root 4096 Aug 5 2019 server
[root@hdss7-21 kubernetes]
[root@hdss7-21 kubernetes]
[root@hdss7-21 server]
[root@hdss7-21 bin]
total 1548804
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 cloud-controller-manager.docker_tag
-rw-r--r-- 1 root root 144437760 Aug 5 2019 cloud-controller-manager.tar
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-apiserver.docker_tag
-rw-r--r-- 1 root root 208390656 Aug 5 2019 kube-apiserver.tar
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-controller-manager.docker_tag
-rw-r--r-- 1 root root 160286208 Aug 5 2019 kube-controller-manager.tar
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-proxy.docker_tag
-rw-r--r-- 1 root root 84282368 Aug 5 2019 kube-proxy.tar
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-scheduler.docker_tag
-rw-r--r-- 1 root root 82675200 Aug 5 2019 kube-scheduler.tar
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]
[root@hdss7-21 bin]
total 884660
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 cloud-controller-manager.docker_tag
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-apiserver.docker_tag
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-controller-manager.docker_tag
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-proxy.docker_tag
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-scheduler.docker_tag
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]
[root@hdss7-21 bin]
total 884660
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 cloud-controller-manager.docker_tag
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-apiserver.docker_tag
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-controller-manager.docker_tag
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-proxy.docker_tag
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-scheduler.docker_tag
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]
[root@hdss7-21 bin]
total 884640
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]
/opt/kubernetes/server/bin
[root@hdss7-21 bin]
[root@hdss7-21 bin]
[root@hdss7-21 cert]
total 0
[root@hdss7-21 cert]
ca.pem 100% 1346 1.9MB/s 00:00
[root@hdss7-21 cert]
ca-key.pem 100% 1679 1.3MB/s 00:00
[root@hdss7-21 cert]
client.pem 100% 1363 1.0MB/s 00:00
[root@hdss7-21 cert]
client-key.pem 100% 1675 743.8KB/s 00:00
[root@hdss7-21 cert]
apiserver.pem 100% 1598 1.0MB/s 00:00
[root@hdss7-21 cert]
apiserver-key.pem 100% 1679 1.1MB/s 00:00
[root@hdss7-21 cert]
total 24
-rw------- 1 root root 1679 Aug 25 21:05 apiserver-key.pem
-rw-r--r-- 1 root root 1598 Aug 25 21:05 apiserver.pem
-rw------- 1 root root 1679 Aug 25 21:05 ca-key.pem
-rw-r--r-- 1 root root 1346 Aug 25 21:05 ca.pem
-rw------- 1 root root 1675 Aug 25 21:05 client-key.pem
-rw-r--r-- 1 root root 1363 Aug 25 21:05 client.pem
[root@hdss7-21 cert]
[root@hdss7-21 bin]
[root@hdss7-21 bin]
[root@hdss7-21 conf]
[root@hdss7-21 conf]
apiVersion: audit.k8s.io/v1beta1
kind: Policy
omitStages:
- "RequestReceived"
rules:
- level: RequestResponse
resources:
- group: ""
resources: ["pods"]
- level: Metadata
resources:
- group: ""
resources: ["pods/log", "pods/status"]
- level: None
resources:
- group: ""
resources: ["configmaps"]
resourceNames: ["controller-leader"]
- level: None
users: ["system:kube-proxy"]
verbs: ["watch"]
resources:
- group: ""
resources: ["endpoints", "services"]
- level: None
userGroups: ["system:authenticated"]
nonResourceURLs:
- "/api*"
- "/version"
- level: Request
resources:
- group: ""
resources: ["configmaps"]
namespaces: ["kube-system"]
- level: Metadata
resources:
- group: ""
resources: ["secrets", "configmaps"]
- level: Request
resources:
- group: ""
- group: "extensions"
- level: Metadata
omitStages:
- "RequestReceived"
[root@hdss7-21 conf]
[root@hdss7-21 conf]
[root@hdss7-21 bin]
total 884652
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
drwxr-xr-x 2 root root 4096 Aug 25 21:05 cert
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
drwxr-xr-x 2 root root 4096 Aug 25 21:08 conf
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 1078 Aug 25 21:09 kube-apiserver.sh
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]
[root@hdss7-21 bin]
./kube-apiserver \
--apiserver-count 2 \
--audit-log-path /data/logs/kubernetes/kube-apiserver/audit-log \
--audit-policy-file ./conf/audit.yaml \
--authorization-mode RBAC \
--client-ca-file ./cert/ca.pem \
--requestheader-client-ca-file ./cert/ca.pem \
--enable-admission-plugins NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota \
--etcd-cafile ./cert/ca.pem \
--etcd-certfile ./cert/client.pem \
--etcd-keyfile ./cert/client-key.pem \
--etcd-servers https://10.4.7.12:2379,https://10.4.7.21:2379,https://10.4.7.22:2379 \
--service-account-key-file ./cert/ca-key.pem \
--service-cluster-ip-range 192.168.0.0/16 \
--service-node-port-range 3000-29999 \
--target-ram-mb=1024 \
--kubelet-client-certificate ./cert/client.pem \
--kubelet-client-key ./cert/client-key.pem \
--log-dir /data/logs/kubernetes/kube-apiserver \
--tls-cert-file ./cert/apiserver.pem \
--tls-private-key-file ./cert/apiserver-key.pem \
--v 2
[root@hdss7-21 bin]
[root@hdss7-21 bin]
[root@hdss7-21 bin]
kube-apiserver-7-21: added process group
[root@hdss7-21 bin]
etcd-server-7-21 RUNNING pid 28560, uptime 0:38:34
kube-apiserver-7-21 STARTING
[root@hdss7-21 bin]
etcd-server-7-21 RUNNING pid 28560, uptime 0:38:41
kube-apiserver-7-21 STARTING
[root@hdss7-21 bin]
etcd-server-7-21 RUNNING pid 28560, uptime 1:08:56
kube-apiserver-7-21 RUNNING pid 29012, uptime 0:30:29
[root@hdss7-21 bin]
total 884652
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
drwxr-xr-x 2 root root 4096 Aug 25 21:05 cert
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
drwxr-xr-x 2 root root 4096 Aug 25 21:08 conf
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 1078 Aug 25 21:09 kube-apiserver.sh
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-21 bin]
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 29013/./kube-apiser
tcp6 0 0 :::6443 :::* LISTEN 29013/./kube-apiser
[root@hdss7-21 bin]
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 29013/./kube-apiser
tcp 0 0 10.4.7.21:34332 10.4.7.21:2379 ESTABLISHED 29013/./kube-apiser
tcp 0 0 10.4.7.21:34376 10.4.7.21:2379 ESTABLISHED 29013/./kube-apiser
tcp 0 0 10.4.7.21:34178 10.4.7.21:2379 ESTABLISHED 29013/./kube-apiser
tcp 0 0 10.4.7.21:39520 10.4.7.22:2379 ESTABLISHED 29013/./kube-apiser
1、下面就是去22上进行部署 ----和21基本上一样的不再多说
[root@hdss7-22 ~]
[root@hdss7-22 src]
total 9620
-rw-r--r-- 1 root root 9850227 May 25 22:31 etcd-v3.1.20-linux-amd64.tar.gz
[root@hdss7-22 src]
The authenticity of host 'hdss7-21.host.com (10.4.7.21)' can't be established.
ECDSA key fingerprint is SHA256:S8lqSXkRnqiGTHxKRSz2BsEbZ45BZTzgVUg611F56/0.
ECDSA key fingerprint is MD5:bb:9d:b7:1f:be:e3:0a:cc:2a:58:5b:13:56:df:c9:82.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hdss7-21.host.com,10.4.7.21' (ECDSA) to the list of known hosts.
root@hdss7-21.host.com's password:
kubernetes-server-linux-amd64-v1.15.2.tar.gz 100% 423MB 121.6MB/s 00:03
[root@hdss7-22 src]
total 442992
-rw-r--r-- 1 root root 9850227 May 25 22:31 etcd-v3.1.20-linux-amd64.tar.gz
-rw-r--r-- 1 root root 443770238 Jun 1 23:25 kubernetes-server-linux-amd64-v1.15.2.tar.gz
[root@hdss7-22 src]
[root@hdss7-22 src]
[root@hdss7-22 opt]
[root@hdss7-22 opt]
[root@hdss7-22 opt]
[root@hdss7-22 kubernetes]
[root@hdss7-22 kubernetes]
[root@hdss7-22 server]
total 4
drwxr-xr-x 2 root root 4096 Aug 5 2019 bin
[root@hdss7-22 server]
[root@hdss7-22 bin]
total 1548800
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 cloud-controller-manager.docker_tag
-rw-r--r-- 1 root root 144437760 Aug 5 2019 cloud-controller-manager.tar
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-apiserver.docker_tag
-rw-r--r-- 1 root root 208390656 Aug 5 2019 kube-apiserver.tar
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-controller-manager.docker_tag
-rw-r--r-- 1 root root 160286208 Aug 5 2019 kube-controller-manager.tar
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-proxy.docker_tag
-rw-r--r-- 1 root root 84282368 Aug 5 2019 kube-proxy.tar
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rw-r--r-- 1 root root 8 Aug 5 2019 kube-scheduler.docker_tag
-rw-r--r-- 1 root root 82675200 Aug 5 2019 kube-scheduler.tar
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-22 bin]
[root@hdss7-22 bin]
[root@hdss7-22 bin]
total 884636
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-22 bin]
[root@hdss7-22 bin]
[root@hdss7-22 bin]
[root@hdss7-22 cert]
root@hdss7-200's password:
ca.pem 100% 1346 1.3MB/s 00:00
[root@hdss7-22 cert]# ll
total 4
-rw-r--r-- 1 root root 1346 Jun 1 23:31 ca.pem
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/ca-key.pem .
root@hdss7-200's password:
ca-key.pem 100% 1679 667.4KB/s 00:00
[root@hdss7-22 cert]
root@hdss7-200's password:
client.pem 100% 1363 321.8KB/s 00:00
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/client-key.pem .
root@hdss7-200's password:
client-key.pem 100% 1675 665.0KB/s 00:00
[root@hdss7-22 cert]
root@hdss7-200's password:
apiserver.pem 100% 1598 652.1KB/s 00:00
[root@hdss7-22 cert]# scp hdss7-200:/opt/certs/apiserver-key.pem .
root@hdss7-200's password:
apiserver-key.pem 100% 1679 1.5MB/s 00:00
[root@hdss7-22 cert]
total 24
-rw------- 1 root root 1679 Jun 1 23:33 apiserver-key.pem
-rw-r--r-- 1 root root 1598 Jun 1 23:33 apiserver.pem
-rw------- 1 root root 1679 Jun 1 23:32 ca-key.pem
-rw-r--r-- 1 root root 1346 Jun 1 23:31 ca.pem
-rw------- 1 root root 1675 Jun 1 23:33 client-key.pem
-rw-r--r-- 1 root root 1363 Jun 1 23:32 client.pem
[root@hdss7-22 cert]
[root@hdss7-22 conf]
root@hdss7-21.host.com's password:
audit.yaml 100% 2224 2.1MB/s 00:00
[root@hdss7-22 conf]# ll
total 4
-rw-r--r-- 1 root root 2224 Jun 1 23:35 audit.yaml
[root@hdss7-22 conf]# vi audit.yaml
[root@hdss7-22 conf]# ll
total 4
-rw-r--r-- 1 root root 2223 Jun 1 23:36 audit.yaml
[root@hdss7-22 conf]# cd ..
[root@hdss7-22 bin]# ls
apiextensions-apiserver cloud-controller-manager hyperkube kube-apiserver kubectl kube-proxy mounter
cert conf kubeadm kube-controller-manager kubelet kube-scheduler
[root@hdss7-22 bin]# pwd
/opt/kubernetes/server/bin
[root@hdss7-22 bin]# scp hdss7-21:/opt/kubernetes/server/bin/kube-apiserver.sh .
root@hdss7-21's password:
kube-apiserver.sh 100% 1078 449.4KB/s 00:00
[root@hdss7-22 bin]
total 884640
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
drwxr-xr-x 2 root root 124 Jun 1 23:33 cert
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
drwxr-xr-x 2 root root 24 Jun 1 23:36 conf
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 1078 Jun 1 23:37 kube-apiserver.sh
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss7-22 bin]
root@hdss7-21's password:
scp: /opt/kubernetes/server/bin/kube-apiserver.ini: No such file or directory
[root@hdss7-22 bin]# scp hdss7-21:/opt/kubernetes/server/bin/kube-apiserver.ini .^C
[root@hdss7-22 bin]# scp hdss7-21:/etc/supervisord.d/kube-apiserver.ini /etc/supervisord.d/kube-apiserver.ini
root@hdss7-21's password:
kube-apiserver.ini 100% 1940 452.2KB/s 00:00
[root@hdss7-22 bin]
[program:kube-apiserver-7-22]
command=/opt/kubernetes/server/bin/kube-apiserver.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
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-apiserver/apiserver.stdout.log ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB ; max
stdout_logfile_backups=4 ;
stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false ; emit events on stdout writes (default false)
[root@hdss7-22 bin]
error: <class 'xmlrpclib.Fault'>, <Fault 92: "CANT_REREAD: The directory named as part of the path /data/logs/kubernetes/kube-apiserver/apiserver.stdout.log does not exist in section 'program:kube-apiserver-7-22' (file: '/etc/supervisord.d/kube-apiserver.ini')">: file: /usr/lib64/python2.7/xmlrpclib.py line: 794
[root@hdss7-22 bin]
[root@hdss7-22 bin]
kube-apiserver-7-22: added process group
[root@hdss7-22 bin]
etcd-server-7-22 RUNNING pid 9387, uptime 2 days, 1:11:24
kube-apiserver-7-22 RUNNING pid 29281, uptime 0:00:50
2、测试是否apiservice是否启动成功了
回到21上也看下是不是也已经为runing了
[root@hdss7-21 bin]
etcd-server-7-21 RUNNING pid 83220, uptime 2 days, 22:33:32
kube-apiserver-7-21 RUNNING pid 91806, uptime 0:22:45
对21和22上都要查看下监听的两个端口
[root@hdss7-22 ~]
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 29282/./kube-apiser
tcp6 0 0 :::6443 :::* LISTEN 29282/./kube-apiser
[root@hdss7-21 ~]
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 91807/./kube-apiser
tcp 0 0 10.4.7.21:36048 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:36220 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:51616 10.4.7.12:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:46266 10.4.7.22:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:35778 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:35984 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:36116 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:36198 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser
tcp 0 0 10.4.7.21:36018 10.4.7.21:2379 ESTABLISHED 91807/./kube-apiser 下面还有很多这里省略不写
三、安装部署主控节点L4反向服务
安装nginx的加入模块时候一直报错 然后我就直接安装了 yum -y install nginx nginx-all-modules.noarch
接下来就是需要在11和12上进行操作了
1、首先我们在11上进行操作,,这里需要用到的是kube-Proxy
HDSS7-11上进行操作,,首先安装nginx
[root@hdss7-11 ~]
2、去给nginx配置主配置文件
解释一下 我们把21和22上的6443端口反代到我们本机的7443端口
/etc/nginx/nginx.conf
stream {
upstream kube-apiserver {
server 10.4.7.21:6443 max_fails=3 fail_timeout=30s;
server 10.4.7.22:6443 max_fails=3 fail_timeout=30s;
}
server {
listen 7443;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass kube-apiserver;
}
}
3、启动nginx
[root@hdss7-11 ~]
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@hdss7-11 ~]
[root@hdss7-11 ~]
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@hdss7-11 ~]
4、安装keepalived
[root@hdss7-11 ~]
5、做一个keepalived的脚本,注意下面的那些解释的内容不需要贴进去
/etc/keepalived/check_port.sh
CHK_PORT=$1
if [ -n "$CHK_PORT" ];then
PORT_PROCESS=`ss -lnt|grep $CHK_PORT|wc -l`
if [ $PORT_PROCESS -eq 0 ];then
echo "Port $CHK_PORT Is Not Used,End."
exit 1
fi
else
echo "Check Port Cant Be Empty!"
fi
[root@hdss7-11 ~]
6、修改配置文件
/etc/keepalived/keepalived.conf
! Configuration File keepalived
global_defs {
router_id 10.4.7.11
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_port.sh 7443"
interval 2
weight -20
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 251
priority 100
advert_int 1
mcast_src_ip 10.4.7.11
nopreempt
authentication {
auth_type PASS
auth_pass 11111111
}
track_script {
chk_nginx
}
virtual_ipaddress {
10.4.7.10
}
}
7、下面是12上做的它做从
/etc/keepalived/keepalived.conf -----注意这个文件有很多不同之处
! Configuration File keepalived
global_defs {
router_id 10.4.7.12
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_port.sh 7443"
interval 2
weight -20
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 251
mcast_src_ip 10.4.7.12
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 11111111
}
track_script {
chk_nginx
}
virtual_ipaddress {
10.4.7.10
}
}
8、启动keepalived 并查看日志
[root@hdss7-11 ~]
[root@hdss7-11 ~]
查看日志 tail -fn 200 /var/log/messages
Jun 2 22:35:19 hdss7-11 Keepalived_vrrp[94421]: /etc/keepalived/check_port.sh 7443 exited with status 1
Jun 2 22:35:21 hdss7-11 Keepalived_vrrp[94421]: /etc/keepalived/check_port.sh 7443 exited with status 1
Jun 2 22:35:23 hdss7-11 Keepalived_vrrp[94421]: /etc/keepalived/check_port.sh 7443 exited with status 1
Jun 2 22:35:25 hdss7-11 Keepalived_vrrp[94421]: /etc/keepalived/check_port.sh 7443 exited with status 1
|