栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

K8S部署ETCD集群

K8S部署ETCD集群

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install new-release bitnami/etcd 
  --set statefulset.replicaCount=3 
  --set persistence.enabled=true 
  --set persistence.size=8Gi 
  --set startFromSnapshot.enabled=true 
  --set startFromSnapshot.existingClaim=my-claim 
  --set startFromSnapshot.snapshotFilename=my-snapshot.db
或者
helm pull  bitnami/etcd --untar
vim values.yaml 添加更多参数
运行
[root@node60 es]# helm install etcd etcd/
NAME: etcd
LAST DEPLOYED: Mon Dec  6 00:07:50 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: etcd
CHART VERSION: 6.10.4
APP VERSION: 3.5.1

** Please be patient while the chart is being deployed **

etcd can be accessed via port 2379 on the following DNS name from within your cluster:

    etcd.default.svc.cluster.local

To create a pod that you can use as a etcd client run the following command:

    kubectl run etcd-client --restart='Never' --image marketplace.azurecr.io/bitnami/etcd:3.5.1-debian-10-r31 --env ROOT_PASSWORD=$(kubectl get secret --namespace default etcd -o jsonpath="{.data.etcd-root-password}" | base64 --decode) --env ETCDCTL_ENDPOINTS="etcd.default.svc.cluster.local:2379" --namespace default --command -- sleep infinity

Then, you can set/get a key using the commands below:

    kubectl exec --namespace default -it etcd-client -- bash
    etcdctl --user root:$ROOT_PASSWORD put /message Hello
    etcdctl --user root:$ROOT_PASSWORD get /message

To connect to your etcd server from outside the cluster execute the following commands:

    kubectl port-forward --namespace default svc/etcd 2379:2379 &
    echo "etcd URL: http://127.0.0.1:2379"

 * As rbac is enabled you should add the flag `--user root:$ETCD_ROOT_PASSWORD` to the etcdctl commands. Use the command below to export the password:

    export ETCD_ROOT_PASSWORD=$(kubectl get secret --namespace default etcd -o jsonpath="{.data.etcd-root-password}" | base64 --decode)

测试
I have no name!@etcd-client:/opt/bitnami/etcd$ etcdctl --user root:$ROOT_PASSWORD get /message
/message
Hello

I have no name!@etcd-client:/opt/bitnami/etcd$  etcdctl --user root:$ROOT_PASSWORD put /message jb 
#####################
I have no name!@etcd-client:/opt/bitnami/etcd$ etcdctl --user root:$ROOT_PASSWORD get /message jb
/message
jb
cli客户端测试
### 获取密码
kubectl get secret --namespace default etcd -o jsonpath="{.data.etcd-root-password}" | base64 -d
[root@node60 etcd-v3.5.1-linux-amd64]# kubectl get svc | grep etcd
etcd            NodePort    10.111.45.140           2379:40488/TCP,2380:60630/TCP   7h14m
etcd-headless   ClusterIP   None                    2379/TCP,2380/TCP               7h14m

[root@node60 etcd-v3.5.1-linux-amd64]# ./etcdctl --user root:siXyhmEXLl --endpoints="http://192.168.8.62:40488" member list -w table
+------------------+---------+--------+------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+------------+
|        ID        | STATUS  |  NAME  |                         PEER ADDRS                         |                                             CLIENT ADDRS                                              | IS LEARNER |
+------------------+---------+--------+------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+------------+
| 45a18acb10aa275e | started | etcd-2 | http://etcd-2.etcd-headless.default.svc.cluster.local:2380 | http://etcd-2.etcd-headless.default.svc.cluster.local:2379,http://etcd.default.svc.cluster.local:2379 |      false |
| 936ce633ac273d75 | started | etcd-1 | http://etcd-1.etcd-headless.default.svc.cluster.local:2380 | http://etcd-1.etcd-headless.default.svc.cluster.local:2379,http://etcd.default.svc.cluster.local:2379 |      false |
| df3b2df95cd5fd29 | started | etcd-0 | http://etcd-0.etcd-headless.default.svc.cluster.local:2380 | http://etcd-0.etcd-headless.default.svc.cluster.local:2379,http://etcd.default.svc.cluster.local:2379 |      false |
+------------------+---------+--------+------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+------------+
[root@node60 etcd-v3.5.1-linux-amd64]#  ./etcdctl --user root:siXyhmEXLl --endpoints="http://192.168.8.62:40488" member list
45a18acb10aa275e, started, etcd-2, http://etcd-2.etcd-headless.default.svc.cluster.local:2380, http://etcd-2.etcd-headless.default.svc.cluster.local:2379,http://etcd.default.svc.cluster.local:2379, false
936ce633ac273d75, started, etcd-1, http://etcd-1.etcd-headless.default.svc.cluster.local:2380, http://etcd-1.etcd-headless.default.svc.cluster.local:2379,http://etcd.default.svc.cluster.local:2379, false
df3b2df95cd5fd29, started, etcd-0, http://etcd-0.etcd-headless.default.svc.cluster.local:2380, http://etcd-0.etcd-headless.default.svc.cluster.local:2379,http://etcd.default.svc.cluster.local:2379, false

[root@node60 etcd-v3.5.1-linux-amd64]# ./etcdctl --user root:siXyhmEXLl --endpoints="http://192.168.8.62:40488" get / --prefix=true --keys-only
/message

再推荐一个etcd客户端 官网
https://etcdmanager.io/
//下载链接
https://github.com/gtamas/etcdmanager/releases/download/1.2.0/etcd-manager-1.2.0-osx.dmg

https://github.com/gtamas/etcdmanager/releases/download/1.2.0/etcd-manager-1.2.0-win64.exe

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/651905.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号