Kubernetes集群存储之etcd
部署
签发ca证书
创建证书请求文件
[root@lab-26 ~]# vi /opt/certs/ca-config.json
{ "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" ] } } } }
创建证书文件
[root@lab-26 ~]# vi /opt/certs/etcd-peer-csr.json
# hosts 只能添加ip地址,地址为可能部署的etcd的服务器上 { "CN": "k8s-etcd", "hosts": [ "172.17.152.106" ], "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "beijing", "L": "beijing", "O": "op", "OU": "ops" } ] }
签发证书
[root@lab-26 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
解压配置etcd
[root@lab-26 certs]# useradd -s /sbin/nologin -M etcd [root@lab-26 certs]# cd /opt/src
软件包下载地址
[root@lab-26 certs]# tar xvf etcd-v3.1.20-linux-amd64.tar.gz -C /opt/ [root@lab-26 src]# cd /opt/ [root@lab-26 opt]# mv etcd-v3.1.20-linux-amd64/ etcd-v3.1.20 [root@lab-26 opt]# ln -s etcd-v3.1.20/ etcd [root@lab-26 opt]# mkdir -p /data/etcd /opt/etcd/certs /data/logs/etcd-server
拷贝证书
[root@lab-26 opt]# cd /opt/etcd/certs/ [root@lab-26 certs]# cp /opt/certs/ca.pem . [root@lab-26 certs]# cp /opt/certs/ca-key.pem . [root@lab-26 certs]# cp /opt/certs/etcd-peer . [root@lab-26 certs]# cp /opt/certs/etcd-peer-key.pem . [root@lab-26 certs]# cp /opt/certs/etcd-peer.pem .
创建启动脚本
[root@lab-26 certs]# vi /opt/etcd/etcd-server-startup.sh
#!/bin/sh ./etcd --name etcd-server-152-106 --data-dir /data/etcd/etcd-server --listen-peer-urls https://172.17.152.106:2380 --listen-client-urls https://172.17.152.106:2379,http://127.0.0.1:2379 --quota-backend-bytes 8000000000 --initial-advertise-peer-urls https://172.17.152.106:2380 --advertise-client-urls https://172.17.152.106:2379,http://127.0.0.1:2379 --initial-cluster etcd-server-152-106=https://172.17.152.106: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@lab-26 certs]# chmod +x /opt/etcd/etcd-server-startup.sh [root@lab-26 certs]# chown -R etcd. /data/etcd [root@lab-26 certs]# chown -R etcd. /data/logs/ [root@lab-26 certs]# chown -R etcd. /opt/etcd/certs
使用supervisor工具管理服务
[root@lab-26 certs]# vi /etc/supervisord.d/etcd-server.ini
[program:etcd-server-152-106] command=/opt/etcd/etcd-server-startup.sh ; the program (relative uses PATH, can take args) numprocs=1 ; number of processes copies to start (def 1) directory=/opt/etcd ; 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=etcd ; setuid to this UNIX account to run the program redirect_stderr=true ; redirect proc stderr to stdout (default false) stdout_logfile=/data/logs/etcd-server/etcd.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) killasgroup=true stopasgroup=true
[root@lab-26 certs]# systemctl start supervisord [root@lab-26 certs]# systemctl enable supervisord [root@lab-26 ctchat]# supervisorctl status etcd-server-152-106 RUNNING pid 22579, uptime 0:01:29
至此部署成功。