etcd-statefulset.yaml 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. apiVersion: apps/v1
  2. kind: StatefulSet
  3. metadata:
  4. name: "etcd"
  5. namespace: discov
  6. labels:
  7. app: "etcd"
  8. spec:
  9. serviceName: "etcd"
  10. replicas: 5
  11. template:
  12. metadata:
  13. name: "etcd"
  14. labels:
  15. app: "etcd"
  16. spec:
  17. volumes:
  18. - name: etcd-pvc
  19. persistentVolumeClaim:
  20. claimName: etcd-pvc
  21. containers:
  22. - name: "etcd"
  23. image: quay.io/coreos/etcd:latest
  24. ports:
  25. - containerPort: 2379
  26. name: client
  27. - containerPort: 2380
  28. name: peer
  29. env:
  30. - name: CLUSTER_SIZE
  31. value: "5"
  32. - name: SET_NAME
  33. value: "etcd"
  34. - name: VOLNAME
  35. valueFrom:
  36. fieldRef:
  37. apiVersion: v1
  38. fieldPath: metadata.name
  39. volumeMounts:
  40. - name: etcd-pvc
  41. mountPath: /var/lib/etcd
  42. subPathExpr: $(VOLNAME) # data mounted respectively in each pod
  43. command:
  44. - "/bin/sh"
  45. - "-ecx"
  46. - |
  47. chmod 700 /var/lib/etcd
  48. IP=$(hostname -i)
  49. PEERS=""
  50. for i in $(seq 0 $((${CLUSTER_SIZE} - 1))); do
  51. PEERS="${PEERS}${PEERS:+,}${SET_NAME}-${i}=http://${SET_NAME}-${i}.${SET_NAME}:2380"
  52. done
  53. exec etcd --name ${HOSTNAME} \
  54. --listen-peer-urls http://0.0.0.0:2380 \
  55. --listen-client-urls http://0.0.0.0:2379 \
  56. --advertise-client-urls http://${HOSTNAME}.${SET_NAME}.discov:2379 \
  57. --initial-advertise-peer-urls http://${HOSTNAME}.${SET_NAME}:2380 \
  58. --initial-cluster ${PEERS} \
  59. --initial-cluster-state new \
  60. --logger zap \
  61. --data-dir /var/lib/etcd \
  62. --auto-compaction-retention 1