一.知识点:

1.headless services 

  NOTE:: 我们在k8s上运行etcd集群,集群间通告身份是使用dns,不能使用pod ip,因为如果pod被重构了ip会变,在这种场景中不能直接使用k8s 的service,因为在集群环境中我们需要直接将service name映射到pod ip,而不是 service ip,这样我们才能完成集群间的身份验证。

2.env

      NOTE: pod还没启动之前怎么能知道pod的ip呢?那我们启动etcd时绑定网卡的ip该怎样拿到呢?这时就可以用env将pod ip 以变量方式传给etcd,这样当pod启动后,etcd就通过env拿到了pod ip,  从而绑定到container 的ip

 

二.架构:

采用三节点的etcd:

分别为:etcd1,etcd2,etcd3

etcd持久数据采用nfs

etcd1.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: etcd1
  labels:
    name: etcd1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: etcd1
  template:
    metadata:
      labels:
        app: etcd1
    spec:
      containers:
      - name: etcd1
        image: myetcd
        imagePullPolicy: IfNotPresent 
        volumeMounts:
        - mountPath: /data
          name: etcd-data
        env:
        - name: host_ip
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        command: ["/bin/sh","-c"]
        args:
        - /tmp/etcd
          --name etcd1
          --initial-advertise-peer-urls http://${host_ip}:2380
          --listen-peer-urls http://${host_ip}:2380
          --listen-client-urls http://${host_ip}:2379,http://127.0.0.1:2379
          --advertise-client-urls http://${host_ip}:2379
          --initial-cluster-token etcd-cluster-1
          --initial-cluster etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380
          --initial-cluster-state new
          --data-dir=/data

      volumes:
      - name: etcd-data
        nfs:
          server: 192.168.85.139
          path: /data/v1
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
猜你喜欢
  • 2021-09-22
  • 2022-12-23
  • 2022-03-10
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
  • 2021-09-05
相关资源
相似解决方案