|
| 1 | +# Deploy RabbitMQ on Kubernetes with the Kubernetes Peer Discovery Plugin to Minikube |
| 2 | + |
| 3 | +This is an **example** that demonstrates a RabbitMQ deployment on Kubernetes with peer discovery |
| 4 | +via `rabbitmq-peer-discovery-k8s` plugin. |
| 5 | + |
| 6 | +## Production (Non-)Suitability |
| 7 | + |
| 8 | +Some values in this example **may or may not be optimal for your deployment**. We encourage users |
| 9 | +to get familiar with the [RabbitMQ Peer Discovery guide](https://www.rabbitmq.com/cluster-formation.html), [RabbitMQ Production Checklist](https://www.rabbitmq.com/production-checklist.html) |
| 10 | +and the rest of [RabbitMQ documentation](https://www.rabbitmq.com/documentation.html) before going into production. |
| 11 | + |
| 12 | +Having [metrics](https://www.rabbitmq.com/monitoring.html), both of RabbitMQ and applications that use it, |
| 13 | +is critically important when making informed decisions about production systems. |
| 14 | + |
| 15 | + |
| 16 | +## Pre-requisites |
| 17 | + |
| 18 | +The example uses, targets or assumes: |
| 19 | + |
| 20 | + * [Minikube](https://kubernetes.io/docs/setup/learning-environment/minikube/) with the [VirtualBox](https://www.virtualbox.org/) driver (other drivers can be used, too) |
| 21 | + * Kubernetes 1.6 |
| 22 | + * RabbitMQ [Docker image](https://hub.docker.com/_/rabbitmq/) (maintained [by Docker, Inc](https://hub.docker.com/_/rabbitmq/)) |
| 23 | + * A [StatefulSets controller](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) |
| 24 | + |
| 25 | + |
| 26 | +## Quick Start with Make |
| 27 | + |
| 28 | +This example comes with a Make target that sets up VirtualBox, Minikube and an example cluster |
| 29 | +in a single command. It can be found under this directory. [Homebrew](https://brew.sh/) will be used to install |
| 30 | +packages and on macOS, VirtualBox [will need OS permissions to install its kernel module](https://developer.apple.com/library/archive/technotes/tn2459/_index.html). |
| 31 | + |
| 32 | +The Homebrew cask installer will ask for your password at some point with a prompt that looks like this: |
| 33 | + |
| 34 | +``` |
| 35 | +Changing ownership of paths required by virtualbox; your password may be necessary |
| 36 | +``` |
| 37 | + |
| 38 | +Please inspect the Make file to be extra sure that you understand and agree to what it does. |
| 39 | +After enabling 3rd party kernel extensions in OS setings, run the default Make target in this directory: |
| 40 | + |
| 41 | +``` |
| 42 | +make |
| 43 | +``` |
| 44 | + |
| 45 | +which is equivalent to first running |
| 46 | + |
| 47 | +``` |
| 48 | +make start-minikube |
| 49 | +``` |
| 50 | + |
| 51 | +to install VirtualBox and Minikube using Homebrew, then |
| 52 | + |
| 53 | +``` |
| 54 | +make run-in-minikube |
| 55 | +``` |
| 56 | + |
| 57 | +to start Minikube and `kubectl apply` the example, and finally |
| 58 | + |
| 59 | +``` |
| 60 | +make wait-for-rabbitmq |
| 61 | +``` |
| 62 | + |
| 63 | +to wait for cluster formation. |
| 64 | + |
| 65 | +Once the changes are applied, follow the steps in the Check Cluster Status section below. |
| 66 | + |
| 67 | +In case you would prefer to install and run Minikube manually, see the following few sections. |
| 68 | + |
| 69 | + |
| 70 | +## Running the Example Manually with Minikube |
| 71 | + |
| 72 | +### Preresuites |
| 73 | + |
| 74 | + * Make sure that VirtualBox is installed |
| 75 | + * Install [`minikube`](https://kubernetes.io/docs/tasks/tools/install-minikube/) and start it with `--vm-driver=virtualbox` |
| 76 | + * Install [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) |
| 77 | + |
| 78 | +### Start Minikube |
| 79 | + |
| 80 | +Start a `minikube` virtual machine: |
| 81 | + |
| 82 | +``` sh |
| 83 | +minikube start --cpus=2 --memory=2040 --disk-size "10 GB" --vm-driver=virtualbox |
| 84 | +``` |
| 85 | + |
| 86 | +### Create a Namespace |
| 87 | + |
| 88 | +Create a Kubernetes namespace for RabbitMQ tests: |
| 89 | + |
| 90 | +``` sh |
| 91 | +kubectl create namespace test-rabbitmq |
| 92 | +``` |
| 93 | + |
| 94 | +### Set Up Kubernetes Permissions |
| 95 | + |
| 96 | +In Kubernetes 1.6 or above, RBAC authorization is enabled by default. |
| 97 | +This example configures RBAC related bits so that the peer discovery plugin is allowed to access |
| 98 | +the nodes information it needs. The `ServiceAccount` and `Role` resources will be created |
| 99 | +in the following step. |
| 100 | + |
| 101 | +### kubectl Apply Things |
| 102 | + |
| 103 | +Deploy the config map, services, a stateful set and so on: |
| 104 | + |
| 105 | +``` sh |
| 106 | +# will apply all files under this directory |
| 107 | +kubectl create -f minikube |
| 108 | +``` |
| 109 | + |
| 110 | +### Check Cluster Status |
| 111 | + |
| 112 | +Wait for a a few minutes for pods to start. Since this example uses a stateful set with ordered |
| 113 | +startup, the pods will be started one by one. To monitor pod startup process, use |
| 114 | + |
| 115 | +``` sh |
| 116 | +kubectl --namespace="test-rabbitmq" get pods |
| 117 | +``` |
| 118 | + |
| 119 | +To run `rabbitmq-diagnostics cluster_status`: |
| 120 | + |
| 121 | +``` sh |
| 122 | +FIRST_POD=$(kubectl get pods --namespace test-rabbitmq -l 'app=rabbitmq' -o jsonpath='{.items[0].metadata.name }') |
| 123 | +kubectl exec --namespace=test-rabbitmq $FIRST_POD -- rabbitmq-diagnostics cluster_status |
| 124 | +``` |
| 125 | + |
| 126 | +to check cluster status. Note that nodes can take some time to start and discover each other. |
| 127 | + |
| 128 | +The output should look something like this: |
| 129 | + |
| 130 | +``` |
| 131 | +Cluster status of node [email protected] ... |
| 132 | +Basics |
| 133 | +
|
| 134 | + |
| 135 | +
|
| 136 | +Disk Nodes |
| 137 | +
|
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +
|
| 142 | +Running Nodes |
| 143 | +
|
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | +
|
| 148 | +Versions |
| 149 | +
|
| 150 | +[email protected]: RabbitMQ 3.8.1 on Erlang 22.1.8 |
| 151 | +[email protected]: RabbitMQ 3.8.1 on Erlang 22.1.8 |
| 152 | +[email protected]: RabbitMQ 3.8.1 on Erlang 22.1.8 |
| 153 | +
|
| 154 | +Alarms |
| 155 | +
|
| 156 | +(none) |
| 157 | +
|
| 158 | +Network Partitions |
| 159 | +
|
| 160 | +(none) |
| 161 | +
|
| 162 | +Listeners |
| 163 | +
|
| 164 | +Node: [email protected], interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication |
| 165 | +Node: [email protected], interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0 |
| 166 | +Node: [email protected], interface: [::], port: 15672, protocol: http, purpose: HTTP API |
| 167 | +Node: [email protected], interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication |
| 168 | +Node: [email protected], interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0 |
| 169 | +Node: [email protected], interface: [::], port: 15672, protocol: http, purpose: HTTP API |
| 170 | +
|
| 171 | +Feature flags |
| 172 | +
|
| 173 | +Flag: drop_unroutable_metric, state: enabled |
| 174 | +Flag: empty_basic_get_metric, state: enabled |
| 175 | +Flag: implicit_default_bindings, state: enabled |
| 176 | +Flag: quorum_queue, state: enabled |
| 177 | +Flag: virtual_host_metadata, state: enabled |
| 178 | +``` |
| 179 | + |
| 180 | +### Use Public Minikube IP Address to Connect |
| 181 | + |
| 182 | +Get the public `minikube` VM IP address: |
| 183 | + |
| 184 | +``` sh |
| 185 | +minikube ip |
| 186 | +# => 192.168.99.104 |
| 187 | +``` |
| 188 | + |
| 189 | +The [ports used](https://www.rabbitmq.com/networking.html#ports) by this example are: |
| 190 | + |
| 191 | + * `amqp://guest:guest@{minikube_ip}:30672`: [AMQP 0-9-1 and AMQP 1.0](https://www.rabbitmq.com/networking.html#ports) client connections |
| 192 | + * `http://{minikube_ip}:31672`: [HTTP API and management UI](https://www.rabbitmq.com/management.html) |
| 193 | + |
| 194 | + |
| 195 | +### Scaling the Number of RabbitMQ Cluster Nodes (Kubernetes Pod Replicas) |
| 196 | + |
| 197 | +``` sh |
| 198 | +# Odd numbers of nodes are necessary for a clear quorum: 3, 5, 7 and so on |
| 199 | +kubectl scale statefulset/rabbitmq --namespace=test-rabbitmq --replicas=5 |
| 200 | +``` |
0 commit comments