# EN: RabbitMQ - Message Broker for async communication between microservices
# VI: RabbitMQ - Message Broker cho giao tiep bat dong bo giua cac microservices
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rabbitmq
  namespace: staging
  labels:
    app: rabbitmq
    environment: staging
    platform: goodgo
    tier: infrastructure
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rabbitmq
  template:
    metadata:
      labels:
        app: rabbitmq
        environment: staging
    spec:
      containers:
      - name: rabbitmq
        image: rabbitmq:3-management-alpine
        ports:
        - containerPort: 5672
          protocol: TCP
        - containerPort: 15672
          protocol: TCP
        env:
        - name: RABBITMQ_DEFAULT_USER
          valueFrom:
            secretKeyRef:
              name: goodgo-secrets
              key: RabbitMQ__Username
        - name: RABBITMQ_DEFAULT_PASS
          valueFrom:
            secretKeyRef:
              name: goodgo-secrets
              key: RabbitMQ__Password
        resources:
          requests:
            memory: "128Mi"
            cpu: "100m"
          limits:
            memory: "256Mi"
            cpu: "250m"
        livenessProbe:
          exec:
            command:
            - rabbitmq-diagnostics
            - ping
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 3
        readinessProbe:
          exec:
            command:
            - rabbitmq-diagnostics
            - check_port_connectivity
          initialDelaySeconds: 15
          periodSeconds: 5
          timeoutSeconds: 3
          failureThreshold: 3
        volumeMounts:
        - name: rabbitmq-data
          mountPath: /var/lib/rabbitmq
      volumes:
      - name: rabbitmq-data
        persistentVolumeClaim:
          claimName: rabbitmq-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  namespace: staging
  labels:
    app: rabbitmq
    environment: staging
spec:
  selector:
    app: rabbitmq
  ports:
  - name: amqp
    protocol: TCP
    port: 5672
    targetPort: 5672
  - name: management
    protocol: TCP
    port: 15672
    targetPort: 15672
  type: ClusterIP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: rabbitmq-pvc
  namespace: staging
  labels:
    app: rabbitmq
    environment: staging
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
