kind: StatefulSet
apiVersion: apps/v1
metadata:
  labels:
    app: rabbitmq
  name: rabbitmq
  namespace: edoc2
spec:
  replicas: 3
  selector:
    matchLabels:
      app: rabbitmq
  serviceName: rabbitmq
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
      - args:
        - -c
        - cp -v /etc/rabbitmq/rabbitmq.conf ${RABBITMQ_CONFIG_FILE}; exec docker-entrypoint.sh
          rabbitmq-server
        command:
        - sh
        env:
        - name: TZ
          value: 'Asia/Shanghai'
        - name: RABBITMQ_ERLANG_COOKIE
          value: 'SWvCP0Hrqv43NG7GybHC95ntCJKoW8UyNFWnBEWG8TY='
        - name: K8S_SERVICE_NAME
          value: rabbitmq
        - name: RABBITMQ_FORCE_BOOT
          value: "yes"
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: RABBITMQ_USE_LONGNAME
          value: "true"
        - name: RABBITMQ_NODENAME
          value: rabbit@$(POD_NAME).$(K8S_SERVICE_NAME).$(POD_NAMESPACE).svc.cluster.local
        - name: RABBITMQ_CONFIG_FILE
          value: /var/lib/rabbitmq/rabbitmq.conf
        image: registry.edoc2.com:5001/edoc2v5/rabbitmq:prod600-v3.8.3
        imagePullPolicy: IfNotPresent
#        livenessProbe:
#          exec:
#            command:
#            - rabbitmq-diagnostics
#            - status
#          initialDelaySeconds: 50
#          periodSeconds: 50
#          timeoutSeconds: 15
        name: rabbitmq
        ports:
        - containerPort: 15672
          name: http
          protocol: TCP
        - containerPort: 5672
          name: amqp
          protocol: TCP
#        readinessProbe:
#          exec:
#            command:
#            - rabbitmq-diagnostics
#            - status
#          initialDelaySeconds: 50
#          periodSeconds: 50
#          timeoutSeconds: 15
        volumeMounts:
        - mountPath: /etc/rabbitmq
          name: config-volume
          readOnly: false
        - mountPath: /var/lib/rabbitmq
          name: rabbitmq-storage
          readOnly: false
        - name: timezone
          mountPath: /etc/localtime
          readOnly: true
      serviceAccountName: rabbitmq
      terminationGracePeriodSeconds: 30
      volumes:
      - name: config-volume
        configMap:
          items:
          - key: rabbitmq.conf
            path: rabbitmq.conf
          - key: enabled_plugins
            path: enabled_plugins
          name: rabbitmq-config
      - name: timezone
        hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
      nodeSelector:
        #"node.middleware.labels": Middleware
        "node.labels.nodelabels": Middleware
  volumeClaimTemplates:
  - metadata:
      name: rabbitmq-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "local-rabbitmq-storage"
      resources:
        requests:
          storage: 300Gi
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: rabbitmq
  name: rabbitmq
  namespace: edoc2
spec:
  ports:
  - name: rmqport
    port: 5672
    targetPort: 5672
    nodePort: 35672
  selector:
    app: rabbitmq
  #type: ClusterIp
  type: NodePort
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: rabbitmq
  name: rabbitmq-manage
  namespace: edoc2
spec:
  ports:
  - name: http
    port: 15672
    nodePort: 35675
    targetPort: 15672
    protocol: TCP
  selector:
    app: rabbitmq
  #type: ClusterIP
  type: NodePort
