Certainly! Here's a straightforward YAML configuration for a Kubernetes RabbitMQ cluster that includes the Erlang cookie:
apiVersion: v1
kind: Service
metadata:
name: rabbitmq
spec:
type: NodePort
ports:
- name: amqp
port: 5672
targetPort: 5672
- name: management
port: 15672
targetPort: 15672
selector:
app: rabbitmq
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: rabbitmq
spec:
selector:
matchLabels:
app: rabbitmq
serviceName: rabbitmq
replicas: 3
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: rabbitmq
spec:
terminationGracePeriodSeconds: 60
containers:
- name: rabbitmq
image: rabbitmq:3.8.16
env:
- name: RABBITMQ_ERLANG_COOKIE
valueFrom:
secretKeyRef:
name: rabbitmq-erlang-cookie
key: erlang-cookie
ports:
- name: amqp
containerPort: 5672
- name: management
containerPort: 15672
volumeMounts:
- name: rabbitmq-data
mountPath: /var/lib/rabbitmq
readinessProbe:
tcpSocket:
port: 5672
initialDelaySeconds: 30
periodSeconds: 10
livenessProbe:
tcpSocket:
port: 5672
initialDelaySeconds: 30
periodSeconds: 10
volumes:
- name: rabbitmq-data
persistentVolumeClaim:
claimName: rabbitmq-pvc
volumeClaimTemplates:
- metadata:
name: rabbitmq-pvc
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
This configuration includes a YAML definition for a Kubernetes service that exposes the RabbitMQ port and management port to allow external access. The StatefulSet definition then creates a RabbitMQ cluster with three replicas, each of which has the Erlang cookie passed in as an environment variable.
To create the secret containing the Erlang cookie, you can use the following command:
kubectl create secret generic rabbitmq-erlang-cookie --from-literal=erlang-cookie=$(openssl rand -hex 32)
This will generate a random string of 32 hexadecimal characters and store it in the rabbitmq-erlang-cookie
secret. The RABBITMQ_ERLANG_COOKIE
environment variable in the YAML definition then reads this secret to set the Erlang cookie.
With this configuration, the Erlang cookie will be seamlessly transferred between all replicas in the RabbitMQ cluster, ensuring that they can communicate with each other without any user-related problems.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-12-15 11:00:00 +0000
Seen: 8 times
Last updated: Mar 27 '22