apiVersion: apps/v1
kind: DaemonSet
metadata:
 name: consul-client
 labels:
  name: consul-client
spec:
  selector:
    matchLabels:
      name: consul-client
  template:
    metadata:
      labels:
        name: consul-client
    spec:
      containers:
        - name: consul
          image: consul:latest
          imagePullPolicy: IfNotPresent
          args:
            - "agent"
            - "-data-dir=/consul/data"
            - "-bind=0.0.0.0"
            - "-client=0.0.0.0"
            - "-advertise=$(POD_IP)"
            - "-retry-join=consul-server-0.consul-server.$(NAMESPACE).svc.cluster.local"
            - "-retry-join=consul-server-1.consul-server.$(NAMESPACE).svc.cluster.local"
            - "-retry-join=consul-server-2.consul-server.$(NAMESPACE).svc.cluster.local"
            - "-domain=cluster.local"
            - "-disable-host-node-id"
          env:
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          lifecycle:
            postStart:
              exec:
                command:
                  - /bin/sh
                  - -c
                  - consul reload
            preStop:
              exec:
                command:
                  - /bin/sh
                  - -c
                  - consul leave
          volumeMounts:
            - name: consul-data-dir
              mountPath: /consul/data
          ports:
            - containerPort: 8500
              hostPort: 8500
              name: http
            - containerPort: 8400
              name: rpc
            - containerPort: 8443
              name: https
            - containerPort: 8301
              name: serf-lan
            - containerPort: 8302
              name: serf-wan
            - containerPort: 8600
              name: consul
            - containerPort: 8300
              name: server
      volumes:
        - name: consul-data-dir
          hostPath:
            path: /Users/xuan/desktop/consul/data
            type: DirectoryOrCreate