rabbit-mq deployment with kubernetes

8/29/2018

I'm in a progress to migrate to kuberenetes from docker-compose. One of the services we're using is rabbit-mq. When I try to deploy rabbit-mq 3.6.16-management I receive the error:

/usr/local/bin/docker-entrypoint.sh: line 382: /etc/rabbitmq/rabbitmq.config: Permission denied.

While it works in docker-compose deployment.

Kuberentes:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: rabbit-mq
  name: rabbit-mq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rabbit-mq
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
         app: rabbit-mq
    spec:
      containers:
      - image: rabbitmq:3.6.16-management
        name: rabbit-mq
        ports:
        - containerPort: 15671
        - containerPort: 5671
        volumeMounts:
        - mountPath: /etc/rabbitmq
          name: rabbit-mq-data
      restartPolicy: Always
      hostname: rabbit-mq
      volumes:
      - name: rabbit-mq-data
        persistentVolumeClaim:
          claimName: rabbit-mq-data

PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app: rabbit-mq-data
  name: rabbit-mq-data
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 16Gi

PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: rabbit-mq-data
  labels:
    type: local
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 16Gi
  hostPath:
    path: "/etc/rabbitmq"

Docker-Compose:

  rabbit-mq:
      image: rabbitmq:3.6.16-management
      ports:
        - "15671:15671"
        - "5671:5671"
      container_name: rabbit-mq
      volumes:
        - rabbit-mq-data:/etc/rabbitmq
      restart: on-failure:5
-- Oren Ashkenazy
docker
kubectl
kubernetes
rabbitmq

1 Answer

9/17/2018

Eventually I've used configmap and secrets to mount files instead of PV and works as expected.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: rabbit-mq
  name: rabbit-mq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rabbit-mq
  template:
    metadata:
      labels:
         app: rabbit-mq
    spec:
      containers:
      - image: rabbitmq:3.6.16-management
        name: rabbit-mq
        ports:
        - containerPort: 15671
        - containerPort: 5671
        volumeMounts:
        - name: rabbit-mq-data
          mountPath: /etc/rabbitmq
          readOnly: false
        - name: mq-secret
          mountPath: /etc/rabbitmq/certfiles
          #readOnly: true
      volumes:
        - name: mq-secret
          secret:
            defaultMode: 420
            secretName: rabbit-mq-secrets
        - configMap:
            defaultMode: 420
            items:
            - key: rabbitmq.config
              path: rabbitmq.config
            name: mq-config
          name: rabbit-mq-data
-- Oren Ashkenazy
Source: StackOverflow