Consul Stateful Set
[oom.git] / kubernetes / consul / charts / consul-server / templates / statefulset.yaml
@@ -12,8 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-apiVersion: extensions/v1beta1
-kind: Deployment
+apiVersion: apps/v1beta1
+kind: StatefulSet
 metadata:
   name: {{ include "common.fullname" . }}
   namespace: {{ include "common.namespace" . }}
@@ -23,6 +23,7 @@ metadata:
     release: {{ .Release.Name }}
     heritage: {{ .Release.Service }}
 spec:
+  serviceName: {{ include "common.servicename" . }}
   replicas: {{ .Values.replicaCount }}
   selector:
     matchLabels:
@@ -32,12 +33,37 @@ spec:
       labels:
         app: {{ include "common.name" . }}
         release: {{ .Release.Name }}
-      name: {{ include "common.name" . }}
     spec:
       imagePullSecrets:
       - name: "{{ include "common.namespace" . }}-docker-registry-key"
       containers:
-      - image: "{{ include "common.repository" . }}/{{ .Values.image }}"
+      - name: {{ include "common.name" . }}
+        image: "{{ include "common.repository" . }}/{{ .Values.image }}"
         command: ["/usr/local/bin/docker-entrypoint.sh"]
-        args: ["agent","-server","-client","0.0.0.0","-enable-script-checks","-bootstrap-expect={{ .Values.replicaCount }}","-ui"]
-        name: {{ include "common.name" . }}
+        args:
+        - "agent"
+        - "-bootstrap-expect={{ .Values.replicaCount }}"
+        - "-enable-script-checks"
+{{- $fullname := include "common.fullname" . -}}
+{{- $servname := include "common.servicename" . -}}
+{{- range $i,$t := until (int .Values.replicaCount)}}
+        - "-retry-join={{ $fullname }}-{{$i}}.{{ $servname }}"
+{{- end }}
+        - "-client=0.0.0.0"
+        - "-server"
+        - "-ui"
+        ports:
+        - containerPort: {{ .Values.service.internalPort }}
+        - containerPort: {{ .Values.service.internalPort2 }}
+        {{- if eq .Values.liveness.enabled true }}
+        livenessProbe:
+          tcpSocket:
+            port: {{ .Values.service.internalPort }}
+          initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
+          periodSeconds: {{ .Values.liveness.periodSeconds }}
+        {{ end -}}
+        readinessProbe:
+          tcpSocket:
+            port: {{ .Values.service.internalPort }}
+          initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
+          periodSeconds: {{ .Values.readiness.periodSeconds }}