How to Deploy RabbitMQ on Kubernetes Using K3s

Message brokering has become an essential component of effective application architecture. RabbitMQ, a popular open-source message broker, excels in handling complex data flows between components and services. Coupling RabbitMQ with Kubernetes via K3s can streamline deployment and scalability. This tutorial aims to guide beginners through setting up RabbitMQ on a Kubernetes cluster managed by K3s, providing a lightweight, easy-to-configure alternative to larger Kubernetes distributions.

What You Will Need

Before diving into the setup process, ensure you have the following:

  • For this tutorial, I have installed Kubernetes usingK3s. Here’s how you can do it.
  • A basic understanding of Linux commands.
  • Access to a terminal or command line interface.
  • Installation rights on your machine (sudo).

Deploying RabbitMQ on Kubernetes

With your K3s cluster up and running, the next step is deploying RabbitMQ.

Using Helm to Deploy RabbitMQ:

Helm is a package manager for Kubernetes, which simplifies application deployment.

Install Helm: First, you need to install Helm on your system:

curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
install Helm on your system

Add the RabbitMQ Helm Chart Repository:

You need to add the official RabbitMQ Helm chart repository to your Helm configuration:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
Add the RabbitMQ Helm Chart Repository:

Install RabbitMQ using Helm:

Now, deploy RabbitMQ using Helm by executing:

helm install my-release bitnami/rabbitmq
deploy RabbitMQ using Helm

This command deploys RabbitMQ with the default configuration. The name my-release is arbitrary and can be replaced with any name you prefer for your RabbitMQ deployment.

Verify the Deployment:

To check if RabbitMQ is running, use:

kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
my-release-rabbitmq-0   1/1     Running   0          80s

Look for the pod with a name starting with my-release-rabbitmq to confirm it’s up and running.

Accessing RabbitMQ

After deployment, you’ll want to access RabbitMQ to start configuring queues and exchanges.

  • Accessing the RabbitMQ Dashboard: RabbitMQ comes with a management dashboard, which is very useful for monitoring and managing your queues.
    • Port Forwarding: To access the dashboard, you need to forward the RabbitMQ port to your local machine:
kubectl port-forward --namespace default svc/my-release-rabbitmq 15672:15672
  • Open a Browser: Open your web browser and navigate to http://localhost:15672/. Note that the default user is user and you can find the password with the following command:
echo "Password      : $(kubectl get secret --namespace default my-release-rabbitmq -o jsonpath="{.data.rabbitmq-password}" | base64 -d)"

Configure a Service to Expose RabbitMQ (Optional)

You can expose RabbitMQ via a Kubernetes service. For external access, a LoadBalancer service is the simplest approach. However, this requires your cloud provider to support LoadBalancers. Alternatively, you can use NodePort.

Using NodePort:

  • Edit your existing service: You can modify the existing RabbitMQ service to type NodePort to expose it on a port across all nodes in your cluster. First, get the name of your RabbitMQ service:
kubectl get svc | grep rabbitmq

Then, edit the service:

kubectl edit svc my-release-rabbitmq

Change type: ClusterIP to type: NodePort and save the file.

  • Find the NodePort: After saving the changes, find out which port was assigned to your RabbitMQ service:
kubectl get svc my-release-rabbitmq
Find the NodePort

Look for the port listed under PORT(S), e.g., 15672:32634/TCP, where 32634 would be the NodePort.

Open your web browser and navigate to:

http://<VPS_IP>:<NodePort>/

Deploying RabbitMQ on a K3s-managed Kubernetes cluster offers a robust solution for managing inter-application messaging in a scalable environment. By following the steps outlined in this tutorial, you have set up a powerful tool that can grow with your needs. Remember to explore more advanced Kubernetes and RabbitMQ features as you become more comfortable with these technologies.

As you continue to expand your deployment, consider exploring more about Kubernetes’ networking, pod security, and RabbitMQ’s clustering capabilities to enhance your setup’s reliability and performance.