Manu Ruiz Ruiz
Manu Ruiz Ruiz

Reputation: 393

Which IP do I have to sub/pub in a mosquitto broker on kubernetes

I have deployed a mosquitto image in a pod in kubernetes with this dockerfile:

FROM eclipse-mosquitto:1.6.7

I downloaded the image an added it to my cluster, using this yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mosquitto-demo
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      bb: web
  template:
    metadata:
      labels:
        bb: web
    spec:
      containers:
      - name: bb-site
        image: mosquittotest:1.0
---
apiVersion: v1
kind: Service
metadata:
  name: mosquitto-entrypoint
  namespace: default
spec:
  type: NodePort
  selector:
    bb: web
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30001

It is running correctly.

My question is: How can I know which IP is the one I should use t sub/pub, and which port?
Do I just have to use the IP of the entrypoint service with the 8080 port?

I'm at a loss here.

Upvotes: 1

Views: 379

Answers (1)

Jonas
Jonas

Reputation: 129065

Do you get an IP-address on the Service?

Using ClusterIP

To have an cluster interal IP, you should set type=ClusterIP on your service:

spec:
  type: ClusterIP

Your clients route it requests to a DNS name for the service, depending on how your namespaces are setup. See DNS for Services and Pods

Using NodePort

If you want to continue using type=NodePort, you can send request to the IP for any Node, but with the specific Node Port number.

Upvotes: 2

Related Questions