Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to setup basic rabbitmq on kubernetes

I need to setup a basic rabbit mq instance (no cluster setup) without persistence or security requirements on a kubernetes cluster.

What I need:

Single rabbit mq pod running as stateful set with replicas = 1, and reach it from inside and outside of cluster via specific url (amgp port and mangement interface port)

What I don't need:

  • persistence
  • security
  • cluster setup

The helm charts I found so far are all adressing production setups with clustering, persistence and so on, but I don't need this stuff as I will use instance only for testing

This is what I have so far:

apiVersion: v1
kind: Service
metadata:
  name: rs-rmq-mgt
spec:
  selector:
    app: rs-rmq
  ports:
  - protocol: TCP
    port: 1337
    targetPort: 15672
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rs-rmq
spec:
  selector:
    matchLabels:
      app: rs-rmq
  serviceName: "rs-rmq"
  replicas: 1
  template:
    metadata:
      labels:
        app: rs-rmq
    spec:
      containers:
      - name: rs-rmq
        image: rabbitmq:management
        ports:
        - containerPort: 25672
        - containerPort: 5672
        - containerPort: 4369
        - containerPort: 15672
like image 445
Martin Avatar asked May 22 '19 11:05

Martin


People also ask

What is RabbitMQ cluster operator?

RabbitMQ Cluster Kubernetes Operator automates provisioning, management, and operations of RabbitMQ clusters running on Kubernetes. RabbitMQ Messaging Topology Operator manages RabbitMQ messaging topologies within a RabbitMQ cluster deployed via the RabbitMQ Cluster Kubernetes Operator.

Is RabbitMQ stateful?

RabbitMQ requires using a Stateful Set to deploy a RabbitMQ cluster to Kubernetes. The Stateful Set ensures that the RabbitMQ nodes are deployed in order, one at a time. This avoids running into a potential peer discovery race condition when deploying a multi-node RabbitMQ cluster.

Is RabbitMQ stateful or stateless?

It is highly recommended that RabbitMQ clusters are deployed using a stateful set. If a stateless set is used recreated nodes will not have their persisted data and will start as blank nodes. This can lead to data loss and higher network traffic volume due to more frequent eager synchronisation of newly joining nodes.


3 Answers

I think the simplest way to do that is using Helm:

helm install stable/rabbitmq

Then just read the instructions in the output notes from the chart :)

like image 94
CoderMan Avatar answered Oct 23 '22 09:10

CoderMan


If you don't need more than a replica and persistent. You can go with a simple pod deployment rather than sts. Please refer sts doc

kubectl run rabbitmq --image=rabbitmq:management --expose --port=15672 --restart=Never
--dry-run -o yaml > rabbitmq.yml

Edit the relevant container ports and create the pod.

kubectl create -f rabbitmq.yml

Expose the service as NodePort.

kubectl expose po rabbitmq --port 15672

Now, you can access it externally via

NodesIP:NodePort

and internally by using,

[svc].[namespace].svc

like image 37
hariK Avatar answered Oct 23 '22 11:10

hariK


Use this StatefulSet yaml file for basic rabbitmq instance:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: rabbitmq
spec:
  replicas: 1
  serviceName: rabbitmq
  selector:
    matchLabels:
      app: rabbitmq
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
      - name: rabbitmq
        image: rabbitmq:3-management
        env:
        - name: "RABBITMQ_ERLANG_COOKIE"
          value: "1WqgH8N2v1qDBDZDbNy8Bg9IkPWLEpu79m6q+0t36lQ="
        volumeMounts:
        - mountPath: /var/lib/rabbitmq
          name: rabbitmq-data
      volumes:
        - name: rabbitmq-data
          hostPath:
            path: /data/rabbitmq
            type: DirectoryOrCreate

like image 4
Hardeep Avatar answered Oct 23 '22 10:10

Hardeep