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/

  1. [rancher@rmaster01 ~]$ docker ps -a -f=name=etcd$
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. cf3240f66065 rancher/coreos-etcd:v3.4.14-rancher1 "/usr/local/bin/etcd…" 8 weeks ago Up 6 minutes etcd
  4. [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
  5. +----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
  6. | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
  7. +----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
  8. | https://192.168.6.102:2379 | 48c8f6426a43d1f1 | 3.4.14 | 92 MB | false | false | 49 | 18502729 | 18502729 | |
  9. | https://192.168.6.101:2379 | e5f985c597c36724 | 3.4.14 | 91 MB | false | false | 49 | 18502729 | 18502729 | |
  10. | https://192.168.6.100:2379 | f4e7ca4943b7b405 | 3.4.14 | 91 MB | true | false | 49 | 18502729 | 18502729 | |
  11. +----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
  12. [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 list
  13. 48c8f6426a43d1f1, started, etcd-rmaster03, https://192.168.6.102:2380, https://192.168.6.102:2379, false
  14. e5f985c597c36724, started, etcd-rmaster02, https://192.168.6.101:2380, https://192.168.6.101:2379, false
  15. f4e7ca4943b7b405, started, etcd-rmaster01, https://192.168.6.100:2380, https://192.168.6.100:2379, false
  16. [rancher@rmaster01 ~]$

证书

  1. [rancher@rmaster01 ssl]$ pwd
  2. /etc/kubernetes/ssl
  3. [rancher@rmaster01 ssl]$ ls
  4. certs kubecfg-kube-controller-manager.yaml kube-etcd-192-168-11-102.pem
  5. kube-apiserver-key.pem kubecfg-kube-node.yaml kube-node-key.pem
  6. kube-apiserver.pem kubecfg-kube-proxy.yaml kube-node.pem
  7. kube-apiserver-proxy-client-key.pem kubecfg-kube-scheduler.yaml kube-proxy-key.pem
  8. kube-apiserver-proxy-client.pem kube-controller-manager-key.pem kube-proxy.pem
  9. kube-apiserver-requestheader-ca-key.pem kube-controller-manager.pem kube-scheduler-key.pem
  10. kube-apiserver-requestheader-ca.pem kube-etcd-192-168-11-100-key.pem kube-scheduler.pem
  11. kube-ca-key.pem kube-etcd-192-168-11-100.pem kube-service-account-token-key.pem
  12. kube-ca.pem kube-etcd-192-168-11-101-key.pem kube-service-account-token.pem
  13. kubecfg-kube-apiserver-proxy-client.yaml kube-etcd-192-168-11-101.pem
  14. kubecfg-kube-apiserver-requestheader-ca.yaml kube-etcd-192-168-11-102-key.pem
  15. [rancher@rmaster01 ssl]$
  1. [rancher@rmaster01 ~]$ docker ps |grep etcd
  2. c93210bbcacc rancher/rke-tools:v0.1.72 "/docker-entrypoint.…" 3 weeks ago Up 6 days etcd-rolling-snapshots
  3. e073d4c5266b rancher/coreos-etcd:v3.4.13-rancher1 "/usr/local/bin/etcd…" 3 weeks ago Up 6 days etcd
  4. [rancher@rmaster01 ~]$
  5. [rancher@rmaster01 ~]$ docker image ls |grep etcd
  6. rancher/coreos-etcd v3.4.13-rancher1 7a8adaf3e7ad 7 months ago 83.8MB
  7. [rancher@rmaster01 ~]$
  1. [rancher@rmaster01 ~]$ docker exec -it c93 bash
  2. bash-5.0#
  3. bash-5.0# etcdctl -v
  4. etcdctl version: 3.3.10
  5. API version: 2
  6. bash-5.0#
  1. [rancher@rmaster01 ~]$ docker exec -it e073 sh
  2. # export ETCDCTL_API=3
  3. # etcdctl member list
  4. 48c8f6426a43d1f1, started, etcd-rmaster03, https://192.168.6.102:2380, https://192.168.6.102:2379, false
  5. e5f985c597c36724, started, etcd-rmaster02, https://192.168.6.101:2380, https://192.168.6.101:2379, false
  6. f4e7ca4943b7b405, started, etcd-rmaster01, https://192.168.6.100:2380, https://192.168.6.100:2379, false
  7. #
  1. [root@rmaster01 ~]# docker exec -it e073d4c5266b sh
  2. # etcdctl endpoint health
  3. https://127.0.0.1:2379 is healthy: successfully committed proposal: took = 31.811534ms
  4. # etcdctl member list
  5. 48c8f6426a43d1f1, started, etcd-rmaster03, https://192.168.6.102:2380, https://192.168.6.102:2379, false
  6. e5f985c597c36724, started, etcd-rmaster02, https://192.168.6.101:2380, https://192.168.6.101:2379, false
  7. f4e7ca4943b7b405, started, etcd-rmaster01, https://192.168.6.100:2380, https://192.168.6.100:2379, false
  1. # etcdctl snapshot save snapshotdb
  2. {"level":"info","ts":1616891288.2478633,"caller":"snapshot/v3_snapshot.go:119","msg":"created temporary db file","path":"snapshotdb.part"}
  3. {"level":"info","ts":"2021-03-28T00:28:08.280Z","caller":"clientv3/maintenance.go:200","msg":"opened snapshot stream; downloading"}
  4. {"level":"info","ts":1616891288.2803595,"caller":"snapshot/v3_snapshot.go:127","msg":"fetching snapshot","endpoint":"https://127.0.0.1:2379"}
  5. {"level":"info","ts":"2021-03-28T00:28:09.231Z","caller":"clientv3/maintenance.go:208","msg":"completed snapshot read; closing"}
  6. {"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}
  7. {"level":"info","ts":1616891289.5304568,"caller":"snapshot/v3_snapshot.go:152","msg":"saved","path":"snapshotdb"}
  8. Snapshot saved at snapshotdb
  9. #

kubeadm

  1. ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \
  2. --cert=/etc/kubernetes/pki/etcd/server.crt \
  3. --key=/etc/kubernetes/pki/etcd/server.key \
  4. --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  5. member list
  6. ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \
  7. --cert=/etc/kubernetes/pki/etcd/server.crt \
  8. --key=/etc/kubernetes/pki/etcd/server.key \
  9. --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  10. snapshot save /var/lib/backup/etcd-snapshot.db
  11. ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \
  12. --cert=/etc/kubernetes/pki/etcd/server.crt \
  13. --key=/etc/kubernetes/pki/etcd/server.key \
  14. --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  15. --write-out=table snapshot status /var/lib/backup/etcd-snapshot.db
  16. ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \
  17. --cert=/etc/kubernetes/pki/etcd/server.crt \
  18. --key=/etc/kubernetes/pki/etcd/server.key \
  19. --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  20. snapshot restore /var/lib/backup/etcd-snapshot.db
  21. ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \
  22. --cert=/etc/kubernetes/pki/etcd/server.crt \
  23. --key=/etc/kubernetes/pki/etcd/server.key \
  24. --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  25. --name master \
  26. --data-dir=/var/lib/etcd \
  27. --skip-hash-check \
  28. --initial-advertise-peer-urls=https://127.0.0.1:2380 \
  29. --initial-cluster=master=https://127.0.0.1:2380 \
  30. snapshot restore /var/lib/backup/etcd-snapshot.db
  31. [root@master ~]# kubectl -n kube-system exec -it etcd-master sh
  32. # ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \
  33. --cert=/etc/kubernetes/pki/etcd/server.crt \
  34. --key=/etc/kubernetes/pki/etcd/server.key \
  35. --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  36. member list> > > >
  37. 3ced1f2dde846660, started, master, https://192.168.11.90:2380, https://192.168.11.90:2379, false
  38. #
  39. # ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \
  40. --cert=/etc/kubernetes/pki/etcd/server.crt \
  41. --key=/etc/kubernetes/pki/etcd/server.key \
  42. --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  43. --write-out=table snapshot status /var/lib/backup/etcd-snapshot.db> > > >
  44. +----------+----------+------------+------------+
  45. | HASH | REVISION | TOTAL KEYS | TOTAL SIZE |
  46. +----------+----------+------------+------------+
  47. | bbf56722 | 34835 | 1349 | 4.5 MB |
  48. +----------+----------+------------+------------+
  49. #
  1. [root@master ~]# cat /etc/kubernetes/manifests/etcd.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. annotations:
  6. kubeadm.kubernetes.io/etcd.advertise-client-urls: https://192.168.11.90:2379
  7. creationTimestamp: null
  8. labels:
  9. component: etcd
  10. tier: control-plane
  11. name: etcd
  12. namespace: kube-system
  13. spec:
  14. containers:
  15. - command:
  16. - etcd
  17. - --advertise-client-urls=https://192.168.11.90:2379
  18. - --cert-file=/etc/kubernetes/pki/etcd/server.crt
  19. - --client-cert-auth=true
  20. - --data-dir=/var/lib/etcd
  21. - --initial-advertise-peer-urls=https://192.168.11.90:2380
  22. - --initial-cluster=master=https://192.168.11.90:2380
  23. - --key-file=/etc/kubernetes/pki/etcd/server.key
  24. - --listen-client-urls=https://127.0.0.1:2379,https://192.168.11.90:2379
  25. - --listen-metrics-urls=http://127.0.0.1:2381
  26. - --listen-peer-urls=https://192.168.11.90:2380
  27. - --name=master
  28. - --peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt
  29. - --peer-client-cert-auth=true
  30. - --peer-key-file=/etc/kubernetes/pki/etcd/peer.key
  31. - --peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt
  32. - --snapshot-count=10000
  33. - --trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt
  34. image: registry.aliyuncs.com/google_containers/etcd:3.4.3-0
  35. imagePullPolicy: IfNotPresent
  36. livenessProbe:
  37. failureThreshold: 8
  38. httpGet:
  39. host: 127.0.0.1
  40. path: /health
  41. port: 2381
  42. scheme: HTTP
  43. initialDelaySeconds: 15
  44. timeoutSeconds: 15
  45. name: etcd
  46. resources: {}
  47. volumeMounts:
  48. - mountPath: /var/lib/etcd
  49. name: etcd-data
  50. - mountPath: /etc/kubernetes/pki/etcd
  51. name: etcd-certs
  52. hostNetwork: true
  53. priorityClassName: system-cluster-critical
  54. volumes:
  55. - hostPath:
  56. path: /etc/kubernetes/pki/etcd
  57. type: DirectoryOrCreate
  58. name: etcd-certs
  59. - hostPath:
  60. path: /var/lib/etcd
  61. type: DirectoryOrCreate
  62. name: etcd-data
  63. status: {}
  64. [root@master ~]#

etcd 命令帮助

  1. # etcdctl -h
  2. NAME:
  3. etcdctl - A simple command line client for etcd3.
  4. USAGE:
  5. etcdctl [flags]
  6. VERSION:
  7. 3.4.3
  8. API VERSION:
  9. 3.4
  10. COMMANDS:
  11. alarm disarm Disarms all alarms
  12. alarm list Lists all alarms
  13. auth disable Disables authentication
  14. auth enable Enables authentication
  15. check datascale Check the memory usage of holding data for different workloads on a given server endpoint.
  16. check perf Check the performance of the etcd cluster
  17. compaction Compacts the event history in etcd
  18. defrag Defragments the storage of the etcd members with given endpoints
  19. del Removes the specified key or range of keys [key, range_end)
  20. elect Observes and participates in leader election
  21. endpoint hashkv Prints the KV history hash for each endpoint in --endpoints
  22. endpoint health Checks the healthiness of endpoints specified in `--endpoints` flag
  23. endpoint status Prints out the status of endpoints specified in `--endpoints` flag
  24. get Gets the key or a range of keys
  25. help Help about any command
  26. lease grant Creates leases
  27. lease keep-alive Keeps leases alive (renew)
  28. lease list List all active leases
  29. lease revoke Revokes leases
  30. lease timetolive Get lease information
  31. lock Acquires a named lock
  32. make-mirror Makes a mirror at the destination etcd cluster
  33. member add Adds a member into the cluster
  34. member list Lists all members in the cluster
  35. member promote Promotes a non-voting member in the cluster
  36. member remove Removes a member from the cluster
  37. member update Updates a member in the cluster
  38. migrate Migrates keys in a v2 store to a mvcc store
  39. move-leader Transfers leadership to another etcd cluster member.
  40. put Puts the given key into the store
  41. role add Adds a new role
  42. role delete Deletes a role
  43. role get Gets detailed information of a role
  44. role grant-permission Grants a key to a role
  45. role list Lists all roles
  46. role revoke-permission Revokes a key from a role
  47. snapshot restore Restores an etcd member snapshot to an etcd directory
  48. snapshot save Stores an etcd node backend snapshot to a given file
  49. snapshot status Gets backend snapshot status of a given file
  50. txn Txn processes all the requests in one transaction
  51. user add Adds a new user
  52. user delete Deletes a user
  53. user get Gets detailed information of a user
  54. user grant-role Grants a role to a user
  55. user list Lists all users
  56. user passwd Changes password of user
  57. user revoke-role Revokes a role from a user
  58. version Prints the version of etcdctl
  59. watch Watches events stream on keys or prefixes
  60. OPTIONS:
  61. --cacert="" verify certificates of TLS-enabled secure servers using this CA bundle
  62. --cert="" identify secure client using this TLS certificate file
  63. --command-timeout=5s timeout for short running command (excluding dial timeout)
  64. --debug[=false] enable client-side debug logging
  65. --dial-timeout=2s dial timeout for client connections
  66. -d, --discovery-srv="" domain name to query for SRV records describing cluster endpoints
  67. --discovery-srv-name="" service name to query when using DNS discovery
  68. --endpoints=[127.0.0.1:2379] gRPC endpoints
  69. -h, --help[=false] help for etcdctl
  70. --hex[=false] print byte strings as hex encoded strings
  71. --insecure-discovery[=true] accept insecure SRV records describing cluster endpoints
  72. --insecure-skip-tls-verify[=false] skip server certificate verification
  73. --insecure-transport[=true] disable transport security for client connections
  74. --keepalive-time=2s keepalive time for client connections
  75. --keepalive-timeout=6s keepalive timeout for client connections
  76. --key="" identify secure client using this TLS key file
  77. --password="" password for authentication (if this option is used, --user option shouldn't include password)
  78. --user="" username[:password] for authentication (prompt if password is not supplied)
  79. -w, --write-out="simple" set the output format (fields, json, protobuf, simple, table)