gpt4 book ai didi

kubernetes - 如何使用Istio创建内部网关?

转载 作者:行者123 更新时间:2023-12-02 11:36:47 24 4
gpt4 key购买 nike

目前,我们已成功设置Istio来创建几个入口网关,例如api.example.com和app.example.com,这些网关将流量路由到具有目标规则等的各种服务。除此以外,我们还希望使用Istio的功能仅用于内部API,但是我们不确定如何设置类似的内容。是否可以使用Istio的网关和VirtualServices CRD在不退出群集的情况下路由流量?如果是这样,我们将如何进行设置?

最佳答案

我会在Arghya Sadhu回答中添加一些内容。

我认为我在另一篇文章中的example是您问题的答案,特别是virtual service网关和主机。这个示例需要附加的目标规则,因为我们有一些子集,这些子集在此处标记了到nginx正确子集的路由,并且它们是在目标规则中定义的。

So, as an example, I would call something like internal-gateway/a or internal-gateway/b, and they would get routed to services A or B



我做了这样的事情

2个Nginx Pod-> 2个服务->虚拟服务

部署1
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx1
spec:
selector:
matchLabels:
run: nginx1
replicas: 1
template:
metadata:
labels:
run: nginx1
app: frontend
spec:
containers:
- name: nginx1
image: nginx
ports:
- containerPort: 80
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello nginx1 > /usr/share/nginx/html/index.html"]

部署2
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx2
spec:
selector:
matchLabels:
run: nginx2
replicas: 1
template:
metadata:
labels:
run: nginx2
app: frontend2
spec:
containers:
- name: nginx2
image: nginx
ports:
- containerPort: 80
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello nginx2 > /usr/share/nginx/html/index.html"]

服务1
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: frontend
spec:
ports:
- port: 80
protocol: TCP
selector:
app: frontend

服务2
apiVersion: v1
kind: Service
metadata:
name: nginx2
labels:
app: frontend2
spec:
ports:
- port: 80
protocol: TCP
selector:
app: frontend2

虚拟服务
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nginxvirt
spec:
hosts:
- nginx.default.svc.cluster.local
- nginx2.default.svc.cluster.local
http:
- name: a
match:
- uri:
prefix: /a
rewrite:
uri: /
route:
- destination:
host: nginx.default.svc.cluster.local
port:
number: 80
- name: b
match:
- uri:
prefix: /b
rewrite:
uri: /
route:
- destination:
host: nginx2.default.svc.cluster.local
port:
number: 80

以上虚拟服务仅在 mesh gateway内部起作用。

您有2个符合2个nginx服务的匹配项。
root@ubu1:/# curl nginx/a
Hello nginx1

root@ubu1:/# curl nginx/b
Hello nginx2

我建议检查istio文档并阅读以下内容:
  • Gateways
  • Virtual Services
  • Destination Rules

  • 和istio示例:
  • bookinfo
  • httpbin

  • So I can make up a DNS name or IP address that doesn't really exist



    我认为您误会了它,它必须存在,但不能存在于网格中。例如,一些不在网格中但您仍可以使用的数据库,例如服务条目,将其连接到网格。

    istio documentation和整个 external services documentation中有维基百科的示例。

    希望对您有帮助。如果您还有其他问题,请告诉我。

    关于kubernetes - 如何使用Istio创建内部网关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59604397/

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