gpt4 book ai didi

kubernetes - 如何在Kubernetes中打开自定义端口

转载 作者:行者123 更新时间:2023-12-02 12:25:50 26 4
gpt4 key购买 nike

我在集群上部署了Rabbit MQ,到目前为止在端口15672上运行良好:http://test.website.com/
但需要打开其他一些端口(25672、15672、15674)。我在yaml中定义如下:

apiVersion: v1
kind: Service
metadata:
name: rabbitmq
spec:
selector:
name: rabbitmq
ports:
- port: 80
name: http
targetPort: 15672
protocol: TCP
- port: 443
name: https
targetPort: 15672
protocol: TCP

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: rabbitmq
spec:
selector:
matchLabels:
app: rabbitmq
strategy:
type: RollingUpdate
template:
metadata:
name: rabbitmq
spec:
containers:
- name: rabbitmq
image: rabbitmq:latest
ports:
- containerPort: 15672
name: http
protocol: TCP
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: rabbitmq
spec:
hosts:
- “test.website.com”
gateways:
- gateway
http:
- match:
- uri:
prefix: /
route:
- destination:
port:
number: 80
host: rabbitmq
如何在yaml文件中设置打开其他端口?

最佳答案

假设Istio Gateway正在为TCP网络连接提供服务,则您可以为两个外部端口组合一个Gateway配置。
这是一个例子:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: port1
protocol: TCP
hosts:
- example.myhost.com
- port:
number: 443
name: port2
protocol: TCP
hosts:
- example.myhost.com
字段 hosts在此标识此 Gateway必须公开的目标地址的列表。
为了对嵌套Pod进行适当的网络路由,请指定 VirtualService及其端口的匹配集:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: rabbitmq-virtual-service
spec:
hosts:
- example.myhost.com
gateways:
- gateway
tcp:
- match:
- port: 80
route:
- destination:
host: app.example.svc.cluster.local
port:
number: 15672
- match:
- port: 443
route:
- destination:
host: app.example.svc.cluster.local
port:
number: 15674
VirtualService上方定义了规则,用于将来自 test.website.com的80和443端口的网络流量分别路由到 rabbitmq服务端口15672、15674。
您可以根据需要调整这些文件以打开其他端口。
看一下: virtualservice-for-a-service-which-exposes-multiple-ports

关于kubernetes - 如何在Kubernetes中打开自定义端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63311599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com