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 wich port? Do I just have to use the IP of the entrypoint service with the 8080 port? Im at a loss here.
Do you get an IP-address on the Service?
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
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.