<p>I saw the example for docker healthcheck of RabbitMQ at <a href="https://github.com/docker-library/healthcheck" rel="noreferrer">docker-library/healthcheck</a>.</p>

<p>I would like to apply a similar mechanism to my Kubernetes deployment to await on Rabbit deployment readiness. I'm doing a similar thing with MongoDB, using a container that busy-waits mongo with some ping command.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app-1
  template:
    metadata:
      labels:
        app: app-1
    spec:
      initContainers:
        - name: wait-for-mongo
          image: gcr.io/app-1/tools/mongo-ping
      containers:
        - name: app-1-service
          image: gcr.io/app-1/service
          ...
</code></pre>

<p>However when I tried to construct such an init container I couldn't find any solution on how to query the health of rabbit from outside its cluster.</p>

<p>The following works without any extra images/scripts, but requires you to enable the <a href="https://www.rabbitmq.com/management.html" rel="nofollow noreferrer">Management Plugin</a>, eg by using the <code>rabbitmq:3.8-management</code> image instead of eg <code>rabbitmq:3.8</code>.</p>
<pre><code>initContainers:
  - name: check-rabbitmq-ready
    image: busybox
    command: [ 'sh', '-c',
        'until wget http://guest:guest@rabbitmq:15672/api/aliveness-test/%2F;
        do echo waiting for rabbitmq; sleep 2; done;' ]
</code></pre>
<p>Specifically, this is waiting until the HTTP Management API is available, and then checking that the default vhost is running healthily.  The <code>%2F</code> refers to the default <code>/</code> vhost, which has to be urlendoded. If using your own vhost, enter that instead.</p>
