how to setup basic rabbitmq on kubernetes
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
Use this StatefulSet
yaml file for basic rabbitmq instance:
apiVersion: apps/v1beta1kind: StatefulSetmetadata: name: rabbitmqspec: 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
The proper way to do it, is to install rabbitmq via dedicated helm-chart (stable/rabbitmq) with helm (Kubernetes package manager). The main reason for that: this way is thoroughly tested and verified by open source community.
If you want to take a shortcut, please refer to the following task from Kubernetes official website: Starting a message queue service (rabbitmq). You will find there links to all necessary manifest files.