apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker
  namespace: mosquitto
spec:
  replicas: 1
  serviceName: broker
  selector:
    matchLabels:
      app: broker
  template:
    metadata:
      labels:
        app: broker
    spec:
      containers:
      - name: broker
        image: eclipse-mosquitto:1.6.9
        ports:
        - containerPort: 1883
          name: mqtt
        - containerPort: 8883
          name: mqttssl
        - containerPort: 9001
          name: ws
        env:
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        volumeMounts:
        - name: conf
          mountPath: /mosquitto/config
          readOnly: false
        - name: secrets
          mountPath: /mosquitto/secrets
          readOnly: true
        - name: data
          mountPath: /mosquitto/data
          readOnly: false
      volumes:
      - name: conf
        configMap:
          name: broker
          defaultMode: 0755
      - name: secrets
        secret:
          secretName: passwd
      securityContext:
        runAsUser: 1883
        runAsGroup: 1883
        fsGroup: 1883
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 10Gi
      storageClassName: hcloud-volumes
