github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/etcd/templates/clusterdefinition.yaml (about) 1 apiVersion: apps.kubeblocks.io/v1alpha1 2 kind: ClusterDefinition 3 metadata: 4 name: etcd 5 labels: 6 {{- include "etcd.labels" . | nindent 4}} 7 spec: 8 type: etcd 9 componentDefs: 10 - name: etcd 11 characterType: etcd 12 workloadType: Consensus 13 rsmSpec: 14 roles: 15 - name: leader 16 accessMode: ReadWrite 17 isLeader: true 18 canVote: true 19 - name: follower 20 accessMode: ReadWrite 21 isLeader: false 22 canVote: true 23 roleProbe: 24 customHandler: 25 - image: quay.io/coreos/etcd:v3.5.6 26 command: 27 - | 28 Status=$(etcdctl --endpoints=127.0.0.1:2379 endpoint status -w simple --command-timeout=300ms --dial-timeout=100m) && 29 IsLeader=$(echo $Status | awk -F ', ' '{print $5}') && 30 IsLearner=$(echo $Status | awk -F ', ' '{print $6}') && 31 if [ "true" = "$IsLeader" ]; then echo -n "leader"; elif [ "true" = "$IsLearner" ]; then echo -n "learner"; else echo -n "follower"; fi 32 roleUpdateMechanism: DirectAPIServerEventUpdate 33 memberUpdateStrategy: BestEffortParallel 34 service: 35 ports: 36 - name: client 37 port: 2379 38 targetPort: client 39 podSpec: 40 containers: 41 - name: etcd 42 imagePullPolicy: IfNotPresent 43 ports: 44 - containerPort: 2379 45 name: client 46 - containerPort: 2380 47 name: peer 48 volumeMounts: 49 - name: data 50 mountPath: /var/run/etcd 51 command: 52 - bin/sh 53 - -c 54 - | 55 echo "start etcd..." 56 PEERS="" 57 # TODO: clusterDomain 'cluster.local' requires configurable 58 DOMAIN=$KB_NAMESPACE".svc{{ .Values.clusterDomain }}" 59 i=0 60 while [ $i -lt $KB_REPLICA_COUNT ]; do 61 if [ $i -ne 0 ]; then 62 PEERS="$PEERS,"; 63 fi; 64 host=$(eval echo \$KB_"$i"_HOSTNAME) 65 host=$host"."$DOMAIN 66 hostname=${KB_CLUSTER_COMP_NAME}-${i} 67 PEERS="$PEERS$hostname=http://$host:2380" 68 i=$(( i + 1)) 69 done 70 # TODO: clusterDomain 'cluster.local' requires configurable 71 MY_PEER=$KB_POD_FQDN{{ .Values.clusterDomain }} 72 exec etcd --name ${HOSTNAME} \ 73 --experimental-initial-corrupt-check=true \ 74 --listen-peer-urls http://0.0.0.0:2380 \ 75 --listen-client-urls http://0.0.0.0:2379 \ 76 --advertise-client-urls http://${MY_PEER}:2379 \ 77 --initial-advertise-peer-urls http://${MY_PEER}:2380 \ 78 --initial-cluster ${PEERS} \ 79 --data-dir /var/run/etcd/default.etcd 80 connectionCredential: 81 username: root 82 password: "" 83 endpoint: "$(SVC_FQDN)" 84 port: "$(SVC_PORT_client)"