apiVersion: batch/v1
kind: Job
metadata:
  name: consul-joiner
spec:
  template:
    metadata:
      name: consul-joiner
    spec:
      containers:
      - name: consul
        image: consul:latest
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        command:
          - consul
          - join
        args: 
        - -http-addr=consul-0.consul.$(NAMESPACE).svc.cluster.local:8500
        - consul-1.consul.$(NAMESPACE).svc.cluster.local
        - consul-2.consul.$(NAMESPACE).svc.cluster.local
      restartPolicy: Never