---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rabbitmq
  labels:
    name: rabbitmq
  namespace: sock-shop
spec:
  selector:
    matchLabels:
      name: rabbitmq
  replicas: 1
  template:
    metadata:
      labels:
        name: rabbitmq
      annotations:
        prometheus.io/scrape: "false"
    spec:
      initContainers:
      - name: configmap-copy
        image: busybox
        command: ['/bin/sh', '-c', 'cp /etc/rabbitmq/files/* /etc/rabbitmq/']
        volumeMounts:
        - name: config-volume
          mountPath: /etc/rabbitmq/files
        - name: config
          mountPath: /etc/rabbitmq
      containers:
      - name: rabbitmq
        image: rabbitmq:3.7.8-management
        ports:
        - name: management
          containerPort: 15672
        - name: rabbitmq
          containerPort: 5672
        - name: dist
          containerPort: 25672
        - name: epmd
          containerPort: 4369
        securityContext:
          capabilities:
            drop:
              - all
            add:
              - CHOWN
              - SETGID
              - SETUID
              - DAC_OVERRIDE
          readOnlyRootFilesystem: false
        env:
          - name: MY_POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          - name: RABBITMQ_USE_LONGNAME
            value: "true"
          - name: RABBITMQ_NODENAME
            value: "rabbit@$(MY_POD_IP)"
          - name: K8S_SERVICE_NAME
            value: "rabbitmq"
          - name: RABBITMQ_ERLANG_COOKIE
            value: "mycookie" 
      - name: rabbitmq-exporter
        image: kbudde/rabbitmq-exporter
        resources:
          requests:
            cpu: 50m
            memory: 50Mi
        ports:
        - name: exporter
          containerPort: 9090
      volumes:
      - name: config
        emptyDir: {}
      - name: config-volume
        configMap:
          name: rabbitmq-config
          items:
          - key: rabbitmq.conf
            path: rabbitmq.conf
          - key: enabled_plugins
            path: enabled_plugins
      nodeSelector:
        beta.kubernetes.io/os: linux
