Kubernetes container cluster deploying ETCD cluster

Install etcd

The binary package download address: https://github.com/etcd-io/etcd/releases/tag/v3.2.12

[[emailprotected] ~]# GOOGLE_URL=https://storage.googleapis.com/etcd
[[emailprotected] ~]# GITHUB_URL=https:// github.com/coreos/etcd/releases/download
[[emailprotected] ~]# DOWNLOAD_URL=${GOOGLE_URL}
[[emailprotected] ~]# ETCD_VER=v3.2.12
[[email Protected] ~]# curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64 .tar.gz


% Total% Received% Xferd Average Speed ​​Time Time Time Current
Dload Upload Total Spent Left Speed
100 10.0M 100 10.0M 0 0 2161k 0 0:00:04 0:00:04 --:--:-- 2789k
[[emailprotected] ~]# ls /tmp
etcd-v3.2.12-linux-amd64. tar.gz
Unzip
[[emailprotected] ~]# tar -zxf /tmp/etcd-v3.2.12-linux-amd64.tar.gz
[[emailprotected] ~] # ls
etcd-v3.2.12-linux-amd6 4
Create a cluster deployment directory
[[emailprotected] ~]# mkdir -p /opt/kubernetes/{bin,cfg,ssl}
[[emailprotected] ~]# tree / opt/kubernetes
/opt/kubernetes
├── bin
├── cfg
└── ssl
[[emailprotected] ~]# mv etcd- v3.2.12-linux-amd64/etcd /opt/kubernetes/bin
[[emailprotected] ~]# mv etcd-v3.2.12-linux-amd64/etcdctl /opt/kubernetes/bin
[ [email protected] ~]# ls /opt/kubernetes/bin
etcd etcdctl
Add configuration file
[[emailprotected] ~]# cat /opt/kubernetes/cfg/etcd
#[Member]
#Specify etcd name
ETCD_NAME="etcd03"
#Data directory
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
#Monitor cluster port
ETCD_LISTEN_PEER_URLS="https://192.168.238.130:2380"
#Monitor data port
ETCD_LISTEN_CLIENT_URLS="https://192.168.238.130:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.238.130:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.238.130:2379"
#Cluster Node information
ETCD_INITIAL_CLUSTER="etcd01=https://192.168.238.129:2380,etcd02=https: //192.168.238.128:2380;etcd03=https://192.168.238.130:2380"
#token
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

[[email Protected] ~]# cat /usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target< br />After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=-/opt/kubernetes /cfg/etcd
ExecStart=/opt/kubernetes/bin/etcd --name=${ETCD_NAME} --data-dir=${ETCD_DATA_DIR} --listen-peer-urls=${ETCD_LISTEN_PEER_URLS} - listen-client-urls=${ETCD_LISTENT_CLIENT_URLS},http://127.0.0.1:2379 --advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} --initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} --initial- cluster=${ETCD_INITIAL_CLUSTER} --initial-cluster-token=${ETCD_INITIAL_CLUSTER} --initial-cluster-state=new --cert-file=/opt/kubernetes/ssl/server.pem --key-file=/ opt/kubernetes/ssl/server-key.pem --peer-cert-file=/o pt/kubernetes/ssl/server.pem --peer-key-file=/opt/kubernetes/ssl/server-key.pem --trusted-ca-file=/opt/kubernetes/ssl/ca.pem --peer -trusted-ca-file=/opt/kubernetes/ssl/ca.pem
Restart=on-failure
LimitNOFILE=65535

[Install]
WantedBy= multi-user.target

The certificate is stored in the specified directory
[[emailprotected] ~]# cp ssl/server*pem ssl/ca*pem /opt/kubernetes/ssl/
[[email Protected] ~]# ls /opt/kubernetes/ssl/
ca-key.pem ca.pem server-key.pem server.pem
start etcd
[[ email Protected] ~]# systemctl start etcd
Job for etcd.service failed because the control process exited with error code. See "systemctl status etcd.service" and "journalctl -xe" for details.
Start Failed to view logs
[[emailprotected] ~]# journalctl -u etcd
-- Logs begin at Tue 2019-07-02 17:22:07 EDT, end at Tue 2019-07-02 17 :58:00 EDT. --
Jul 02 17:57:59 master systemd[1]: Starting Etcd Server...
Jul 02 17:57:59 master etcd[8172]: invalid value ",http://127.0.0.1:2379" for flag -li sten-
Jul 02 17:57:59 master etcd[8172]: usage: etcd [flags]
Jul 02 17:57:59 master etcd[8172]: start an etcd server
Jul 02 17:57:59 master etcd[8172]: etcd --version
Jul 02 17:57:59 master etcd[8172]: show the version of etcd
Jul 02 17:57:59 master etcd[8172]: etcd -h | --help
Jul 02 17:57:59 master etcd[8172]: show the help information about etcd
Jul 02 17:57:59 master etcd[ 8172]: etcd --config-file
Jul 02 17:57:59 master etcd[8172]: path to the server configuration file
Jul 02 17:57:59 master etcd[8172]: etcd gateway
Jul 02 17:57:59 master etcd[8172]: run the stateless pass-through etcd TCP connection forwa
Jul 02 17:57:59 master etcd[8172]: etcd grpc-proxy< br />Jul 02 17:57:59 master etcd[8172]: run the stateless etcd v3 gRPC L7 reverse proxy
Jul 02 17:57:59 master systemd[1]: etcd.service: main process exited, code=exited, status=2
Jul 02 17:57:59 master systemd[1]: Failed to start Etcd Server.
Jul 02 17:57:59 m aster systemd[1]: Unit etcd.service entered failed state.
Jul 02 17:57:59 master systemd[1]: etcd.service failed.
Jul 02 17:57:59 master systemd[ 1]: etcd.service holdoff time over, scheduling restart.
Jul 02 17:57:59 master systemd[1]: Stopped Etcd Server.
Jul 02 17:57:59 master systemd[1] : Starting Etcd Server...
Jul 02 17:57:59 master etcd[8176]: invalid value ",http://127.0.0.1:2379" for flag -listen-
Jul 02 17 :57:59 master etcd[8176]: usage: etcd [flags]
Jul 02 17:57:59 master etcd[8176]: start an etcd server
Jul 02 17:57:59 master etcd [8176]: etcd --version
Jul 02 17:57:59 master etcd[8176]: show the version of etcd
Jul 02 17:57:59 master etcd[8176]: etcd -h | --help
Jul 02 17:57:59 master etcd[8176]: show the help information about etcd
Jul 02 17:57:59 master etcd[8176]: etcd --config-file
Jul 02 17:57:59 master etcd[8176]: path to the server configuration file
Jul 02 17:57:59 master etcd[8176]: etcd gateway
Jul 02 17:57:59 master etcd[8176]: run the stateless pass-through etcd TCP connection forwa
Jul 02 17:57:59 master etcd[8176]: etcd grpc-proxy
Jul 02 17:57:59 master etcd[8176]: run the stateless etcd v3 gRPC L7 reverse proxy
Jul 02 17:57:59 master systemd[1]: etcd.service: main process exited, code=exited , status=2
Jul 02 17:57:59 master systemd[1]: Failed to start Etcd Server.
Jul 02 17:57:59 master systemd[1]: Unit etcd.service entered failed state.
Jul 02 17:57:59 master systemd[1]: etcd.service failed.
Jul 02 17:57:59 master systemd[1]: etcd.service holdoff time over, scheduling restart .
Jul 02 17:57:59 master systemd[1]: Stopped Etcd Server.
Jul 02 17:57:59 master systemd[1]: Starting Etcd Server...
lines 1-42

[[email protected] ~]# tail -n 20 /var/log/messages
Jul 2 17:58:00 localhost etcd: etcd --version
Jul 2 17:58:00 localhost etcd: show the version of etcd
Jul 2 17:58:00 localhost etcd: etcd -h | --help
Jul 2 17:58:00 localhost etcd: show the help information about etcd
Jul 2 17:58:00 localhost etcd: etcd --config-file
Jul 2 17:58:00 localhost etcd: path to the server configuration file
Jul 2 17:58:00 localhost etcd: etcd gateway
Jul 2 17:58:00 localhost etcd: run the stateless pass-through etcd TCP connection forwarding proxy
Jul 2 17:58:00 localhost etcd: etcd grpc-proxy
Jul 2 17:58:00 localhost etcd: run the stateless etcd v3 gRPC L7 reverse proxy
Jul 2 17:58:00 localhost systemd: etcd.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Jul 2 17:58:00 localhost systemd: Failed to start Etcd Server.
Jul 2 17:58:00 localhost systemd: Unit etcd.service entered failed state.
Jul 2 17:58:00 localhost systemd: etcd.service failed.
Jul 2 17:58:00 localhost systemd: etcd.service holdoff time over, scheduling restart.
Jul 2 17:58:00 localhost systemd: Stopped Etcd Server.
Jul 2 17:5 8:00 localhost systemd: start request repeated too quickly for etcd.service
Jul 2 17:58:00 localhost systemd: Failed to start Etcd Server.
Jul 2 17:58:00 localhost systemd: Unit etcd.service entered failed state.
Jul 2 17:58:00 localhost systemd: etcd.service failed.

[[emailprotected] ~]# systemctl status etcd
● etcd.service-Etcd Server
Loaded: loaded (/usr/lib/systemd/system/etcd.service; disabled; vendor preset: disabled)
Active: activating (start) since Tue 2019-07- 02 18:32:55 EDT; 16s ago
Main PID: 8138 (etcd)
Memory: 20.5M
CGroup: /system.slice/etcd.service
└─8138 /opt/kubernetes/bin/etcd --name=etcd03 --data-dir=/var/lib/etcd/default.etcd --listen-peer-urls=https://192.168.238.130:2380 --listen- client-urls=https://192.168.238.13...

Jul 02 18:33:09 master etcd[8138]: a7e9807772a004c5 received MsgVoteResp from a7e9807772a004c5 at term 72
Jul 02 18 :33:09 master etcd[8138]: a7e9 807772a004c5 [logterm: 1, index: 3] sent MsgVote request to 203750a5948d27da at term 72
Jul 02 18:33:09 master etcd[8138]: a7e9807772a004c5 [logterm: 1, index: 3] sent MsgVote request to c858c42725f38881 at term 72
Jul 02 18:33:10 master etcd[8138]: health check for peer 203750a5948d27da could not connect: dial tcp 192.168.238.128:2380: i/o timeout
Jul 02 18:33 :10 master etcd[8138]: health check for peer c858c42725f38881 could not connect: dial tcp 192.168.238.129:2380: i/o timeout
Jul 02 18:33:11 master etcd[8138]: a7e9807772a004c5 is starting a new election at term 72
Jul 02 18:33:11 master etcd[8138]: a7e9807772a004c5 became candidate at term 73
Jul 02 18:33:11 master etcd[8138]: a7e9807772a004c5 received MsgVoteResp from a7e9807772a004c5 at term 73
Jul 02 18:33:11 master etcd[8138]: a7e9807772a004c5 [logterm: 1, index: 3] sent MsgVote request to 203750a5948d27da at term 73
Jul 02 18:33:11 master etcd[8138]: a7e9807772a004c5 [logterm: 1, index : 3] sent MsgVote request to c858c42725f38881 at term 73
[[emailprotected] ~]# ps -ef|grep etcd
root 8138 1 0 18:32? 00:00:00 /opt/kubernetes /bin/etcd --name=etcd03 --data-dir=/var/lib/etcd/default.etcd --listen-peer-urls=https://192.168.238.130:2380 --listen-client-urls= https://192.168.238.130:2379,http://127.0.0.1:2379 --advertise-client-urls=https://192.168.238.130:2379 --initial-advertise-peer-urls=https:// 192.168.238.130:2380 --initial-cluster=etcd01=https://192.168.238.129:2380,etcd02=https://192.168.238.128:2380,etcd03=https://192.168.238.130:2380 --initial- cluster-token=etcd01=https://192.168.238.129:2380,etcd02=https://192.168.238.128:2380,etcd03=https://192.168.238.130:2380 --initial-cluster-state=new - cert-file=/opt/kubernetes/ssl/server.pem --key-file=/opt/kubernetes/ssl/server-key.pem --peer-cert-file=/opt/kubernetes/ssl/server.pem --peer-key-file=/opt/kubernetes/ssl/server-key.pem --trusted-ca-file=/opt/kubernetes/ssl/ca.pem --peer-trusted- ca-file=/opt/kubernetes/ssl/ca.pem
root 8147 8085 0 18:34 pts/0 00:00:00 grep --color=auto etcd
To this master node deployment is complete
Generating a secret-free login key between nodes
[[emailprotected] ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory'/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
1b :b9:49:23:fc:32:64:6f:72:bd:77:d5:98:28:d4:a0 [emailprotected]
The key's randomart image is:
+- -[ RSA 2048]----+
| |
|. |
|. O |
|. E... |
| = S. . o.|
| o = B.. oo|
| + O ... |
| * ... |
| ... |
+-----------------+
[[email protected] ~]# ls /root/.ssh/
id_ rsa id_rsa.pub
Distribute the key to each node
[[emailprotected] ~]# ssh-copy-id [emailprotected]
The authenticity of host '192.168.238.129 (192.168. 238.129)' can't be established.
ECDSA key fingerprint is d2:7e:40:ca:2b:fb:be:53:f3:2c:8c:e7:54:08:3d:d4.< br />Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed - if you are prompted now it is to install the new keys
[ email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh'[emailprotected]'"
and check to make sure that only the key(s) you wanted were added.

[[email Protected] ~]# ssh-copy-id [email Protected]
The authenticity of host '192.168.238.128 (192.168.238.128)' can't be established.
ECDSA key fingerprint is d2:7e:40:ca:2b:fb:be:53:f3:2c:8c :e7:54:08:3d:d4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed - if you are prompted now it is to install the new keys
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine , with: "ssh'[email protected]'"
and check to make sure that only the key(s) you wanted were added.
Test password-free login
[[emailprotected] ~]# ssh [email protected]
Last login: Tue Jul 2 17:23:09 2019 from 192.168.238.1
[[emailprotected] ~]# hostname
node01
Node 1 creates etcd installation directory
[[emailprotected] ~]# mkdir -p /opt/kubernetes/{bin,cfg,ssl}
Master node sends binary package to node01
[[ email protected] ~]# scp -r /opt/kubernetes/bin/ [email protected]:/opt/kubernetes/
etcd 100% 17MB 17.0MB/s 00:00
etcdctl 100% 15MB 14.5MB/s 00:01
node01 View files
[[emailprotected] ~]# ls /opt/kubernetes/ bin/
etcd etcdctl
The master node sends the configuration file to node01
[[emailprotected] ~]# scp -r /opt/kubernetes/cfg/ [emailprotected]:/opt/kubernetes /
etcd
[[emailprotected] ~]# scp -r /usr/lib/systemd/system/etcd.service [emailprotected]:/usr/lib/systemd/system
etcd.service
node01 View file
[[emailprotected] ~]# ls /opt/kubernetes/cfg/
etcd
[[emailprotected] ~]# ll /usr /lib/systemd/system/etcd.service
-rw-r--r-- 1 root root 996 Jul 2 20:55 /usr/lib/systemd/system/etcd.service
Master node Send the digital certificate to node01
[[emailprotected] ~]# scp -r /opt/kubernetes/ssl/ [emailprotected]:/opt/kubernetes/
server-key.pem 100% 1675 1.6KB/s 00:00
server.pem 100% 1489 1.5KB/s 00:00
ca-key.pem 100% 1679 1.6KB/s 00 :00
ca.pem
node01 View file
[[email protected] ~]# ls /opt/kubernetes/ssl/
ca-key.pem ca.pem server- key.pem server.pem
Modify configuration file
[[emailprotected] ~]# cat /opt/kubernetes/cfg/etcd
#[Member]
ETCD_NAME="etcd01 "
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.238.129:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.238.129 :2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.238.129:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.238.129:2379"
ETCD_INITIAL_CLUSTER="etcd01=https: //192.168.238.129:2380,etcd02=https://192.168.238.128:2380,etcd03=https://192.168.238.130:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE=" new"
Start
[[emailprotected] ~]# systemctl start etcd
[[emailprotected] ~]# ps -ef|grep etcd
root 8702 1 0 21: 01? 00:00:00 /opt/kubernetes/bin/etcd --name=etcd01 --data-dir=/var/lib/etcd/default.etcd --listen-peer-urls=https://192.168. 238.129:2380 --listen-client-urls=https://192.168.238.129:2379,http://127.0.0.1:2379 --advertise-client-urls=https://192.168.238.129:2379 --initial -advertise-peer-urls=https://192.168.238.129:2380 --initial-cluster=etcd01=https://192.168.238.129:2380,etcd02=https://192.168.238.128:2380,etcd03=https: //192.168.238.130:2380 --initial-cluster-token=etcd01=https://1 92.168.238.129:2380,etcd02=https://192.168.238.128:2380,etcd03=https://192.168.238.130:2380 --initial-cluster-state=new --cert-file=/opt/kubernetes/ssl /server.pem --key-file=/opt/kubernetes/ssl/server-key.pem --peer-cert-file=/opt/kubernetes/ssl/server.pem --peer-key-file=/opt /kubernetes/ssl/server-key.pem --trusted-ca-file=/opt/kubernetes/ssl/ca.pem --peer-trusted-ca-file=/opt/kubernetes/ssl/ca.pem
root 8709 7875 0 21:02 pts/0 00:00:00 grep --color=auto etcd
[[emailprotected] ~]# systemctl status etcd
● etcd.service-Etcd Server
Loaded: loaded (/usr/lib/systemd/system/etcd.service; disabled; vendor preset: disabled)
Active: activating (start) since Tue 2019-07-02 21:01:39 EDT; 54s ago
Main PID: 8702 (etcd)
Memory: 6.2M
CGroup: /system.slice/etcd.service
└─8702 /opt/kubernetes/bin /etcd --name=etcd01 --data-dir=/var/lib/etcd/default.etcd --listen-peer-urls=https://192.168.238.129:2380 --listen-client-urls =https://192.168.238.12...

Jul 02 21:02:32 node01 etcd[8702]: c858c42725f38881 is starting a new election at term 36
Jul 02 21:02 :32 node01 etcd[8702]: c858c42725f38881 became candidate at term 37
Jul 02 21:02:32 node01 etcd[8702]: c858c42725f38881 received MsgVoteResp from c858c42725f38881 at term 37
Jul 02 21:02:32 node01 etcd[8702]: c858c42725f38881 [logterm: 1, index: 3] sent MsgVote request to 203750a5948d27da at term 37
Jul 02 21:02:32 node01 etcd[8702]: c858c42725f38881 [logterm: 1, index: 3 ] sent MsgVote request to a7e9807772a004c5 at term 37
Jul 02 21:02:33 node01 etcd[8702]: c858c42725f38881 is starting a new election at term 37
Jul 02 21:02:33 node01 etcd[8702 ]: c858c42725f38881 became candidate at term 38
Jul 02 21:02:33 node01 etcd[8702]: c858c42725f38881 received MsgVoteResp from c858c42725f38881 at term 38
Jul 02 21:02:33 node01 etcd[8702]: c858c42725f38881 [logterm: 1, index: 3] sent MsgVote request to 203750a5948d27da at term 38
Jul 02 21:02:33 node01 etcd[8702]: c858c42725f38881 [logterm: 1, index: 3] sent MsgVote request to a7e9807772a004c5 at term 38
Set boot-up auto-start
[[email Protected] ~]# systemctl enable etcd
Created symlink from /etc/systemd/system/multi-user.target.wants/etcd.service to /usr/lib/systemd/system/etcd.service.
Deploy node02 in the same way

Check cluster status

Set environment variables
[[emailprotected] ~]# tail -n 1 /etc/profile
PATH=/opt/kubernetes/bin:$PATH
[[emailprotected] ~]# source /etc/profile
[[emailprotected] ~]# which etcd
/opt /kubernetes/bin/etcd
[[emailprotected] ~]# which etcdctl
/opt/kubernetes/bin/etcdctl
[[emailprotected] ~]# etcdctl --ca-file =/opt/kubernetes/ssl/ca.pem --cert-file=/opt/kubernetes/ssl/server.pem --key-file=/opt/kubernetes/ssl/server-key.pem --endpoints=" https://192.168.238.130:2379,https://192.168.238.129:2379,https://192.168.238.128:2379" cluster-health
cluster may be unhealthy: failed to list members
Error: client: etcd cluster is unavailable or misconfigured; error #0: client: endpoint https://192.168.238.130:2379 exceeded header timeout
; error #1: client: endpoint https://192.168.238.128:2379 exceeded header timeout
; error #2: client: endpoint https://192.168.238.129:2379 exceeded header timeout

error #0: client: endpoint https://192.168.238.130:2379 exceeded header timeout
error #1: client: endpoint https://192.168.238.128:2379 exceeded header timeout
error #2: client: endpoint https://192.168.238.129:2379 exceeded header timeout< br />The failure may be caused by firewall or selinux

[[emailprotected] ~]# etcdctl --ca-file=/opt/kubernetes/ssl/ca.pem --cert-file =/opt/kubernetes/ssl/server.pem --key-file=/opt/kubernetes/ssl/server-key.pem --endpoints="https://192.168.238.130:2379,https://192.168. 238.129:2379,https://192.168.238.128:2379" cluster-health
member 203750a5948d27da is healthy: got healthy result from https://192.168.238.128:2379
member a7e9807772a 004c5 is healthy: got healthy result from https://192.168.238.130:2379
member c858c42725f38881 is healthy: got healthy result from https://192.168.238.129:2379
cluster is healthy

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2402 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.