<p>I create a yaml file to create rabbitmq kubernetes cluster. I can see pods. But when I write kubectl get deployment. I cant see there. I can't access to rabbitmq ui page.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: rabbit
  name: rabbit
spec:
  ports:
  - port: 5672
    protocol: TCP
    name: mqtt
  - port: 15672
    protocol: TCP
    name: ui
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rabbit
spec:
  serviceName: rabbit
  replicas: 3
  selector:
    matchLabels:
      app: rabbit
  template:
    metadata:
      labels:
        app: rabbit
    spec:
      containers:
        - name: rabbitmq
          image: rabbitmq
      nodeSelector:
        rabbitmq: "clustered"
</code></pre>

newUser
<p>@arghya-sadhu's answer is correct.</p>

<p><strong>NB</strong> I'm unfamiliar with RabbitMQ but you may need to use a different image (see <a href="https://hub.docker.com/_/rabbitmq" rel="nofollow noreferrer">'Management Plugin`</a>) to include the UI.</p>

<p>See below for more details.</p>

<p>You should be able to hack your way to the UI on one (!) of the Pods via:</p>

<pre class="lang-sh prettyprint-override"><code>PORT=8888
kubectl port-forward pod/rabbit-0 --namespace=${NAMESPACE} ${PORT}:15672
</code></pre>

<p>And then browse <code>localhost:${PORT}</code> (if <code>8888</code> is unavailable, try another). </p>

<p>I <strong>suspect</strong> (!) this won't work unless you use the image with the management plugin. </p>

<h3>Plus</h3>

<ul>
<li>The <code>Service</code> needs to select the <code>StatefulSet</code>'s Pods</li>
</ul>

<p>Within the Service <code>spec</code> you should add perhaps:</p>

<pre><code>selector:
  app: rabbit
</code></pre>

<ul>
<li>Presumably (!?) you are using a private repo (because you have <code>imagePullSecrets</code>).</li>
</ul>

<p>If you don't and wish to use DockerHub, you may remove the <code>imagePullSecrets</code> section.</p>

<ul>
<li>It's useful to document (!) container ports albeit not mandatory:</li>
</ul>

<p>In the <code>StatefulSet</code></p>

<pre><code>ports:
- containerPort: 5672
- containerPort: 15672
</code></pre>

<h3>Debug</h3>

<pre class="lang-sh prettyprint-override"><code>NAMESPACE="default" # Or ...
</code></pre>

<p>Ensure the StatefulSet is created:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get statesfulset/rabbit --namespace=${NAMESPACE}
</code></pre>

<p>Check the Pods:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get pods --selector=app=rabbit --namespace=${NAMESPACE}
</code></pre>

<p>You can check the the Pods are bound to a (!) Service:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl describe endpoints/rabbit --namespace=${NAMESPACE}
</code></pre>

<p><strong>NB</strong> You should see 3 addresses (one per Pod)</p>

<p>Get the NodePort either:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get service/rabbit --namespace=${NAMESPACE} --output=json
kubectl describe service/rabbit --namespace=${NAMESPACE}
</code></pre>

<p>You will <strong>need</strong> to use the NodePort to access both the MQTT endpoint and the UI. </p>
