如何使用Istio在Kubernetes上运行Mosquito



我在订阅和发布运行在Kubernetes集群上的Mosquitto服务器时遇到问题。

我知道我的服务和吊舱正在工作。我可以使用我的mosquitto服务作为主机从集群内部订阅和发布。

我还有一个可工作的HTTPS网关,因此我可以访问https://mosquittourl.com.br从外面,我可以看到它到达我在1883港口的蚊子集装箱。集装箱日志:

New connection from 127.0.0.1 on port 1883.
Client <unknown> disconnected due to protocol error.

我想这是预期的行为。因为我是通过https而不是mqtt访问它的。

现在,我无法使用连接到容器

$ mosquitto_pub --url mqtt://mosquittourl.com.br:<port>/test

如何正确设置Istio资源,以便订阅并发布到mosquito服务器?有没有一种方法可以将Istio配置为接受mqtt请求并将其重定向到我的mosquito服务?

我最近能够让Istio设置将TLS加密的MQTT连接路由到Mosquito在Kubernetes上的一个容器中运行。您应该使用TLS作为Istio网关中端口的protocol。最终,Istio可能会像使用gRPC和Mongo一样,将MQTT作为一种选项来支持,但目前您需要将TCP用于未加密的MQTT流量,将TLS用于安全的MQTT连接。

你需要确保正确配置一些东西才能使其正常工作。

  1. Istio操作员配置文件yaml文件

    对于为Istio配置主负载均衡器的IstioOperator,您需要确保设置了正确的端口。对于安全的MQTT流量,即8883(从技术上讲,您可以使用任何端口,但8883是默认端口(。

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
meshConfig:
accessLogFile: /dev/stdout
components:
egressGateways:
- name: istio-egressgateway
enabled: true
k8s:
resources:
requests:
cpu: 10m
memory: 40Mi
ingressGateways:
- name: istio-ingressgateway
enabled: true
k8s:
resources:
requests:
cpu: 10m
memory: 40Mi
service:
ports:
- port: 15021
targetPort: 15021
name: status-port
- port: 31400
targetPort: 31400
name: tcp
# This is the port where sni routing happens
- port: 15443
targetPort: 15443
name: tls
- port: 8883
targetPort: 8883
name: mqtt-secure
pilot:
k8s:
env:
- name: PILOT_TRACE_SAMPLING
value: "100"
resources:
requests:
cpu: 10m
memory: 100Mi
values:
global:
proxy:
resources:
requests:
cpu: 10m
memory: 40Mi
pilot:
autoscaleEnabled: false
gateways:
istio-egressgateway:
autoscaleEnabled: false
istio-ingressgateway:
autoscaleEnabled: false
runAsRoot: true
  1. Istio网关yaml文件

这里的重要部分是确保您在Kubernetes机密中指定了已经拥有的SSL证书的名称,并使用与在IstioOperator中相同的端口,并确保协议是TLS。tls:块告诉网关使用指定的SSL证书进行TLS终止。

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: my-mqtt-ssl-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 8883
name: mqtt-secure
protocol: TLS
hosts:
- "*"
tls:
credentialName: cert-my.certname.com
mode: SIMPLE
privateKey: sds
serverCertificate: sds
  1. Istio虚拟服务yaml文件

最后一步是设置一个Istio虚拟服务,该服务从Istio网关接收流量并将其路由到正确的pod。在目的地更新您的吊舱名称。另一个方面是在端口8883上匹配,并在端口1883上将流量重新路由到mosquito,因为流量在Istio网关中已被TLS终止。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-mqtt-vs
spec:
hosts:
- "*"
gateways:
- my-mqtt-ssl-gateway
tcp:
- match:
- port: 8883
route:
- destination:
host: my-mqtt-broker-pod-name
port:
number: 1883

最新更新