简体   繁体   中英

can't seen in kubernetes cluster

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.

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"

@arghya-sadhu's answer is correct.

NB I'm unfamiliar with RabbitMQ but you may need to use a different image (see 'Management Plugin` ) to include the UI.

See below for more details.

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

PORT=8888
kubectl port-forward pod/rabbit-0 --namespace=${NAMESPACE} ${PORT}:15672

And then browse localhost:${PORT} (if 8888 is unavailable, try another).

I suspect (!) this won't work unless you use the image with the management plugin.

Plus

  • The Service needs to select the StatefulSet 's Pods

Within the Service spec you should add perhaps:

selector:
  app: rabbit
  • Presumably (!?) you are using a private repo (because you have imagePullSecrets ).

If you don't and wish to use DockerHub, you may remove the imagePullSecrets section.

  • It's useful to document (!) container ports albeit not mandatory:

In the StatefulSet

ports:
- containerPort: 5672
- containerPort: 15672

Debug

NAMESPACE="default" # Or ...

Ensure the StatefulSet is created:

kubectl get statesfulset/rabbit --namespace=${NAMESPACE}

Check the Pods:

kubectl get pods --selector=app=rabbit --namespace=${NAMESPACE}

You can check the the Pods are bound to a (!) Service:

kubectl describe endpoints/rabbit --namespace=${NAMESPACE}

NB You should see 3 addresses (one per Pod)

Get the NodePort either:

kubectl get service/rabbit --namespace=${NAMESPACE} --output=json
kubectl describe service/rabbit --namespace=${NAMESPACE}

You will need to use the NodePort to access both the MQTT endpoint and the UI.

statefulsets and deployments are different kubernetes resources. You have created statefulsets. That's why you don't see deployments. If you do

kubectl get statefulset you should see it and also both statefulset and deployment creates pod finally so you should be able to see rabbitmq pods if you do kubectl get pods

Since you have created a Nodeport service. You should be able to access it via http://nodeip:nodeport where nodeip is ip of any worker node in your kubernetes cluster.

You can get to know what is the Nodeport(a number between 30000-32767) by

kubectl describe services rabbit 

Here is the doc on accessing a Nodeport service from outside the cluster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM