我的 minikube 上有以下 Mosquitto 设置:
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mosquitto
namespace: mosquitto
spec:
replicas: 1
selector:
matchLabels:
name: mosquitto
template:
metadata:
labels:
name: mosquitto
spec:
containers:
- name: mosquitto
image: eclipse-mosquitto:2.0.12
ports:
- containerPort: 1883
volumeMounts:
- name: mosquitto-config
mountPath: /mosquitto/config/mosquitto.conf
subPath: mosquitto.conf
volumes:
- name: mosquitto-config
configMap:
name: mosquitto-configmap
配置图:
apiVersion: v1
kind: ConfigMap
metadata:
name: mosquitto-configmap
namespace: mosquitto
data:
mosquitto.conf: |-
listener 1883
allow_anonymous true
服务:
apiVersion: v1
kind: Service
metadata:
name: mosquitto-service
spec:
type: NodePort
selector:
name: mosquitto
ports:
- protocol: TCP
port: 1883
targetPort: 1883
nodePort: 30007
现在我想从我的局域网访问我的部署。在我的主机 Windows 机器上使用 MQTT-Explorer 进行测试。使用 mqtt://localhost:30007 不起作用。已知该设置与端口转发一起使用。
$ k port-forward mosquitto-66d69df7c9-zrvgt 1111:1883
Forwarding from 127.0.0.1:1111 -> 1883
Forwarding from [::1]:1111 -> 1883
Handling connection for 1111
我想我误解了服务部分。最后,服务应该可以从我的 LAN 中访问:
额外问题:如何将服务路由到 mqtt.local 之类的东西?Kubernetes Ingress 对我也不起作用,猜测是因为它仅用于 HTTP