apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rabbitmq
spec:
  serviceName: rabbitmq
  replicas: 3
  selector:
    matchLabels:
      app: rabbitmq
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      terminationGracePeriodSeconds: 10
      nodeSelector:
        mq-node: "yes"
      volumes:
      - name: rabbitmq-config
        configMap:
          name: rabbitmq-configmap
      - name: host-time
        hostPath:
          path: /etc/localtime
      containers:        
      - name: rabbitmq-autocluster
        image: my-registry:5000/rabbitmq-zj:20180201
        ports:
          - name: http
            protocol: TCP
            containerPort: 15672
          - name: amqp
            protocol: TCP
            containerPort: 5672
        livenessProbe:
          exec:
            command: ["rabbitmqctl", "status"]
          initialDelaySeconds: 180
          timeoutSeconds: 5
          periodSeconds: 60
          failureThreshold: 2
        readinessProbe:
          exec:
            command: ["rabbitmqctl", "status"]
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 60
          failureThreshold: 1
        imagePullPolicy: IfNotPresent
        securityContext:
          capabilities: {}
          privileged: true
        volumeMounts:
        - name: rabbitmq-data
          mountPath: /var/lib/rabbitmq/mnesia
        - name: rabbitmq-log
          mountPath: /var/log/rabbitmq
        - name: rabbitmq-config
          mountPath: /tmp/rabbitmq_config
        - name: host-time
          mountPath: /etc/localtime
        env:
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: MY_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: K8S_HOSTNAME_SUFFIX
          value: ".rabbitmq.default.svc.cluster.local."
        - name: RABBITMQ_USE_LONGNAME
          value: "true"
        - name: AUTOCLUSTER_LOG_LEVEL
          value: "warn"
        - name: RABBITMQ_NODENAME
          value: "rabbit@$(MY_POD_NAME)$(K8S_HOSTNAME_SUFFIX)"
        - name: AUTOCLUSTER_TYPE
          value: "k8s"
        - name: RABBITMQ_NODE_TYPE
          value: "disc"
        - name: AUTOCLUSTER_DELAY
          value: "10"
        - name: AUTOCLUSTER_CLEANUP
          value: "true"
        - name: CLEANUP_WARN_ONLY
          value: "true"
        - name: K8S_SCHEME
          value: "http"
        - name: K8S_HOST
          value: "172.20.0.12"
        - name: K8S_ADDRESS_TYPE
          value: "hostname"
        - name: K8S_PORT
          value: "8080"
        - name: RABBITMQ_ERLANG_COOKIE
          valueFrom: 
            secretKeyRef:
              name: erlang.cookie
              key: erlang.cookie
  volumeClaimTemplates:
  - metadata:
      name: rabbitmq-data
      annotations:
        volume.beta.kubernetes.io/storage-class: "fast"
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 2Gi
  - metadata:
      name: rabbitmq-log
      annotations:
        volume.beta.kubernetes.io/storage-class: "fast"
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 2Gi
