apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nats
  labels:
    component: nats
spec:
  serviceName: nats
  replicas: 3
  selector:
    matchLabels:
      component: nats
  template:
    metadata:
      labels:
        component: nats
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
                - key: component
                  operator: In
                  values:
                    - nats
            topologyKey: kubernetes.io/hostname
      containers:
      - name: nats
        image: nats:1.1.0
        args: [ "--config", "/etc/nats/config/nats.conf"]
        volumeMounts:
          - name: config-volume
            mountPath: /etc/nats/config
        ports:
        - containerPort: 4222
          name: client
        - containerPort: 6222
          name: cluster
        - containerPort: 8222
          name: monitor
        livenessProbe:
          httpGet:
            path: /
            port: 8222
          initialDelaySeconds: 10
          timeoutSeconds: 5
      volumes:
      - name: config-volume
        configMap:
          name: nats-config
