---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: consul
  labels:
    app: consul
spec:
  serviceName: consul
  replicas: 3
  selector:
    matchLabels:
      app: consul
  template:
    metadata:
      labels:
        app: consul
    spec:
      containers:
        - name: consul
          image: consul:1.6.2
          imagePullPolicy: IfNotPresent
          args:
            - "agent"
            - "-config-file=/etc/consul/config/server.json"
          resources:
            limits:
              cpu: 500m
              memory: 500Mi
            requests:
              cpu: 500m
              memory: 500Mi
          volumeMounts:
            - name: consul-server-config
              mountPath: /etc/consul/config
            - name: consul-data
              mountPath: /consul/data
          ports:
            - name: http
              containerPort: 8500
            - name: https
              containerPort: 8443
            - name: rpc
              containerPort: 8400
            - name: serflan-tcp
              protocol: "TCP"
              containerPort: 8301
            - name: serflan-udp
              protocol: "UDP"
              containerPort: 8301
            - name: serfwan-tcp
              protocol: "TCP"
              containerPort: 8302
            - name: serfwan-udp
              protocol: "UDP"
              containerPort: 8302
            - name: server
              containerPort: 8300
            - name: consuldns
              containerPort: 8600
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
      volumes:
        - name: consul-server-config
          configMap:
            name: consul-server-config
  volumeClaimTemplates:
    - metadata:
        name: consul-data
      spec:
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 2Gi
