rancher
https://rancher.com/docs/rancher/v2.x/en/troubleshooting/kubernetes-components/etcd/
[
](https://rancher.com/docs/rancher/v2.5/en/troubleshooting/kubernetes-components/etcd/)
https://github.com/rancher/rke/issues/2512
https://rancher.com/docs/rancher/v2.5/en/troubleshooting/kubernetes-components/etcd/
[rancher@rmaster01 ~]$ docker ps -a -f=name=etcd$CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMEScf3240f66065 rancher/coreos-etcd:v3.4.14-rancher1 "/usr/local/bin/etcd…" 8 weeks ago Up 6 minutes etcd[rancher@rmaster01 ~]$ docker exec -e ETCDCTL_ENDPOINTS=$(docker exec etcd /bin/sh -c "etcdctl member list | cut -d, -f5 | sed -e 's/ //g' | paste -sd ','") etcd etcdctl endpoint status --write-out table+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+| https://192.168.6.102:2379 | 48c8f6426a43d1f1 | 3.4.14 | 92 MB | false | false | 49 | 18502729 | 18502729 | || https://192.168.6.101:2379 | e5f985c597c36724 | 3.4.14 | 91 MB | false | false | 49 | 18502729 | 18502729 | || https://192.168.6.100:2379 | f4e7ca4943b7b405 | 3.4.14 | 91 MB | true | false | 49 | 18502729 | 18502729 | |+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+[rancher@rmaster01 ~]$ docker exec -e ETCDCTL_ENDPOINTS=$(docker exec etcd /bin/sh -c "etcdctl member list | cut -d, -f5 | sed -e 's/ //g' | paste -sd ','") etcd etcdctl member list48c8f6426a43d1f1, started, etcd-rmaster03, https://192.168.6.102:2380, https://192.168.6.102:2379, falsee5f985c597c36724, started, etcd-rmaster02, https://192.168.6.101:2380, https://192.168.6.101:2379, falsef4e7ca4943b7b405, started, etcd-rmaster01, https://192.168.6.100:2380, https://192.168.6.100:2379, false[rancher@rmaster01 ~]$
证书
[rancher@rmaster01 ssl]$ pwd/etc/kubernetes/ssl[rancher@rmaster01 ssl]$ lscerts kubecfg-kube-controller-manager.yaml kube-etcd-192-168-11-102.pemkube-apiserver-key.pem kubecfg-kube-node.yaml kube-node-key.pemkube-apiserver.pem kubecfg-kube-proxy.yaml kube-node.pemkube-apiserver-proxy-client-key.pem kubecfg-kube-scheduler.yaml kube-proxy-key.pemkube-apiserver-proxy-client.pem kube-controller-manager-key.pem kube-proxy.pemkube-apiserver-requestheader-ca-key.pem kube-controller-manager.pem kube-scheduler-key.pemkube-apiserver-requestheader-ca.pem kube-etcd-192-168-11-100-key.pem kube-scheduler.pemkube-ca-key.pem kube-etcd-192-168-11-100.pem kube-service-account-token-key.pemkube-ca.pem kube-etcd-192-168-11-101-key.pem kube-service-account-token.pemkubecfg-kube-apiserver-proxy-client.yaml kube-etcd-192-168-11-101.pemkubecfg-kube-apiserver-requestheader-ca.yaml kube-etcd-192-168-11-102-key.pem[rancher@rmaster01 ssl]$
[rancher@rmaster01 ~]$ docker ps |grep etcdc93210bbcacc rancher/rke-tools:v0.1.72 "/docker-entrypoint.…" 3 weeks ago Up 6 days etcd-rolling-snapshotse073d4c5266b rancher/coreos-etcd:v3.4.13-rancher1 "/usr/local/bin/etcd…" 3 weeks ago Up 6 days etcd[rancher@rmaster01 ~]$[rancher@rmaster01 ~]$ docker image ls |grep etcdrancher/coreos-etcd v3.4.13-rancher1 7a8adaf3e7ad 7 months ago 83.8MB[rancher@rmaster01 ~]$
[rancher@rmaster01 ~]$ docker exec -it c93 bashbash-5.0#bash-5.0# etcdctl -vetcdctl version: 3.3.10API version: 2bash-5.0#
[rancher@rmaster01 ~]$ docker exec -it e073 sh# export ETCDCTL_API=3# etcdctl member list48c8f6426a43d1f1, started, etcd-rmaster03, https://192.168.6.102:2380, https://192.168.6.102:2379, falsee5f985c597c36724, started, etcd-rmaster02, https://192.168.6.101:2380, https://192.168.6.101:2379, falsef4e7ca4943b7b405, started, etcd-rmaster01, https://192.168.6.100:2380, https://192.168.6.100:2379, false#
[root@rmaster01 ~]# docker exec -it e073d4c5266b sh# etcdctl endpoint healthhttps://127.0.0.1:2379 is healthy: successfully committed proposal: took = 31.811534ms# etcdctl member list48c8f6426a43d1f1, started, etcd-rmaster03, https://192.168.6.102:2380, https://192.168.6.102:2379, falsee5f985c597c36724, started, etcd-rmaster02, https://192.168.6.101:2380, https://192.168.6.101:2379, falsef4e7ca4943b7b405, started, etcd-rmaster01, https://192.168.6.100:2380, https://192.168.6.100:2379, false
# etcdctl snapshot save snapshotdb{"level":"info","ts":1616891288.2478633,"caller":"snapshot/v3_snapshot.go:119","msg":"created temporary db file","path":"snapshotdb.part"}{"level":"info","ts":"2021-03-28T00:28:08.280Z","caller":"clientv3/maintenance.go:200","msg":"opened snapshot stream; downloading"}{"level":"info","ts":1616891288.2803595,"caller":"snapshot/v3_snapshot.go:127","msg":"fetching snapshot","endpoint":"https://127.0.0.1:2379"}{"level":"info","ts":"2021-03-28T00:28:09.231Z","caller":"clientv3/maintenance.go:208","msg":"completed snapshot read; closing"}{"level":"info","ts":1616891289.5301962,"caller":"snapshot/v3_snapshot.go:142","msg":"fetched snapshot","endpoint":"https://127.0.0.1:2379","size":"23 MB","took":1.282092525}{"level":"info","ts":1616891289.5304568,"caller":"snapshot/v3_snapshot.go:152","msg":"saved","path":"snapshotdb"}Snapshot saved at snapshotdb#
kubeadm
ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \--cert=/etc/kubernetes/pki/etcd/server.crt \--key=/etc/kubernetes/pki/etcd/server.key \--cacert=/etc/kubernetes/pki/etcd/ca.crt \member listETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \--cert=/etc/kubernetes/pki/etcd/server.crt \--key=/etc/kubernetes/pki/etcd/server.key \--cacert=/etc/kubernetes/pki/etcd/ca.crt \snapshot save /var/lib/backup/etcd-snapshot.dbETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \--cert=/etc/kubernetes/pki/etcd/server.crt \--key=/etc/kubernetes/pki/etcd/server.key \--cacert=/etc/kubernetes/pki/etcd/ca.crt \--write-out=table snapshot status /var/lib/backup/etcd-snapshot.dbETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \--cert=/etc/kubernetes/pki/etcd/server.crt \--key=/etc/kubernetes/pki/etcd/server.key \--cacert=/etc/kubernetes/pki/etcd/ca.crt \snapshot restore /var/lib/backup/etcd-snapshot.dbETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \--cert=/etc/kubernetes/pki/etcd/server.crt \--key=/etc/kubernetes/pki/etcd/server.key \--cacert=/etc/kubernetes/pki/etcd/ca.crt \--name master \--data-dir=/var/lib/etcd \--skip-hash-check \--initial-advertise-peer-urls=https://127.0.0.1:2380 \--initial-cluster=master=https://127.0.0.1:2380 \snapshot restore /var/lib/backup/etcd-snapshot.db[root@master ~]# kubectl -n kube-system exec -it etcd-master sh# ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \--cert=/etc/kubernetes/pki/etcd/server.crt \--key=/etc/kubernetes/pki/etcd/server.key \--cacert=/etc/kubernetes/pki/etcd/ca.crt \member list> > > >3ced1f2dde846660, started, master, https://192.168.11.90:2380, https://192.168.11.90:2379, false## ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \--cert=/etc/kubernetes/pki/etcd/server.crt \--key=/etc/kubernetes/pki/etcd/server.key \--cacert=/etc/kubernetes/pki/etcd/ca.crt \--write-out=table snapshot status /var/lib/backup/etcd-snapshot.db> > > >+----------+----------+------------+------------+| HASH | REVISION | TOTAL KEYS | TOTAL SIZE |+----------+----------+------------+------------+| bbf56722 | 34835 | 1349 | 4.5 MB |+----------+----------+------------+------------+#
[root@master ~]# cat /etc/kubernetes/manifests/etcd.yamlapiVersion: v1kind: Podmetadata:annotations:kubeadm.kubernetes.io/etcd.advertise-client-urls: https://192.168.11.90:2379creationTimestamp: nulllabels:component: etcdtier: control-planename: etcdnamespace: kube-systemspec:containers:- command:- etcd- --advertise-client-urls=https://192.168.11.90:2379- --cert-file=/etc/kubernetes/pki/etcd/server.crt- --client-cert-auth=true- --data-dir=/var/lib/etcd- --initial-advertise-peer-urls=https://192.168.11.90:2380- --initial-cluster=master=https://192.168.11.90:2380- --key-file=/etc/kubernetes/pki/etcd/server.key- --listen-client-urls=https://127.0.0.1:2379,https://192.168.11.90:2379- --listen-metrics-urls=http://127.0.0.1:2381- --listen-peer-urls=https://192.168.11.90:2380- --name=master- --peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt- --peer-client-cert-auth=true- --peer-key-file=/etc/kubernetes/pki/etcd/peer.key- --peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt- --snapshot-count=10000- --trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crtimage: registry.aliyuncs.com/google_containers/etcd:3.4.3-0imagePullPolicy: IfNotPresentlivenessProbe:failureThreshold: 8httpGet:host: 127.0.0.1path: /healthport: 2381scheme: HTTPinitialDelaySeconds: 15timeoutSeconds: 15name: etcdresources: {}volumeMounts:- mountPath: /var/lib/etcdname: etcd-data- mountPath: /etc/kubernetes/pki/etcdname: etcd-certshostNetwork: truepriorityClassName: system-cluster-criticalvolumes:- hostPath:path: /etc/kubernetes/pki/etcdtype: DirectoryOrCreatename: etcd-certs- hostPath:path: /var/lib/etcdtype: DirectoryOrCreatename: etcd-datastatus: {}[root@master ~]#
etcd 命令帮助
# etcdctl -hNAME:etcdctl - A simple command line client for etcd3.USAGE:etcdctl [flags]VERSION:3.4.3API VERSION:3.4COMMANDS:alarm disarm Disarms all alarmsalarm list Lists all alarmsauth disable Disables authenticationauth enable Enables authenticationcheck datascale Check the memory usage of holding data for different workloads on a given server endpoint.check perf Check the performance of the etcd clustercompaction Compacts the event history in etcddefrag Defragments the storage of the etcd members with given endpointsdel Removes the specified key or range of keys [key, range_end)elect Observes and participates in leader electionendpoint hashkv Prints the KV history hash for each endpoint in --endpointsendpoint health Checks the healthiness of endpoints specified in `--endpoints` flagendpoint status Prints out the status of endpoints specified in `--endpoints` flagget Gets the key or a range of keyshelp Help about any commandlease grant Creates leaseslease keep-alive Keeps leases alive (renew)lease list List all active leaseslease revoke Revokes leaseslease timetolive Get lease informationlock Acquires a named lockmake-mirror Makes a mirror at the destination etcd clustermember add Adds a member into the clustermember list Lists all members in the clustermember promote Promotes a non-voting member in the clustermember remove Removes a member from the clustermember update Updates a member in the clustermigrate Migrates keys in a v2 store to a mvcc storemove-leader Transfers leadership to another etcd cluster member.put Puts the given key into the storerole add Adds a new rolerole delete Deletes a rolerole get Gets detailed information of a rolerole grant-permission Grants a key to a rolerole list Lists all rolesrole revoke-permission Revokes a key from a rolesnapshot restore Restores an etcd member snapshot to an etcd directorysnapshot save Stores an etcd node backend snapshot to a given filesnapshot status Gets backend snapshot status of a given filetxn Txn processes all the requests in one transactionuser add Adds a new useruser delete Deletes a useruser get Gets detailed information of a useruser grant-role Grants a role to a useruser list Lists all usersuser passwd Changes password of useruser revoke-role Revokes a role from a userversion Prints the version of etcdctlwatch Watches events stream on keys or prefixesOPTIONS:--cacert="" verify certificates of TLS-enabled secure servers using this CA bundle--cert="" identify secure client using this TLS certificate file--command-timeout=5s timeout for short running command (excluding dial timeout)--debug[=false] enable client-side debug logging--dial-timeout=2s dial timeout for client connections-d, --discovery-srv="" domain name to query for SRV records describing cluster endpoints--discovery-srv-name="" service name to query when using DNS discovery--endpoints=[127.0.0.1:2379] gRPC endpoints-h, --help[=false] help for etcdctl--hex[=false] print byte strings as hex encoded strings--insecure-discovery[=true] accept insecure SRV records describing cluster endpoints--insecure-skip-tls-verify[=false] skip server certificate verification--insecure-transport[=true] disable transport security for client connections--keepalive-time=2s keepalive time for client connections--keepalive-timeout=6s keepalive timeout for client connections--key="" identify secure client using this TLS key file--password="" password for authentication (if this option is used, --user option shouldn't include password)--user="" username[:password] for authentication (prompt if password is not supplied)-w, --write-out="simple" set the output format (fields, json, protobuf, simple, table)
