【发布时间】:2021-12-31 23:19:30
【问题描述】:
我试图了解与应定义的命名空间相关的 VirtualService 和 DestinationRule 资源,以及它们是否真的是命名空间资源,或者它们也可以被视为集群范围的资源。
我有以下场景:
- 前端服务(web-frontend)访问后端服务(客户)。
- 前端服务部署在前端命名空间中
- 后端服务(客户)部署在后端命名空间中
- 后端服务客户有 2 个版本(2 个部署),一个与版本 v1 相关,一个与版本 v2 相关。
- clusterIP 服务的默认行为是在 2 个部署(v1 和 v2)之间对请求进行负载平衡,我的目标是通过创建 DestinationRule 和 VirtualService 将流量仅定向到部署版本 v1。李>
- 我想了解的是,定义此类 DestinationRule 和 VirtualService 资源的适当命名空间是哪个。我应该在前端命名空间还是后端命名空间中创建必要的 DestinationRule 和 VirtualService 资源?
在前端命名空间中,我有 web 前端部署和相关服务如下:
apiVersion: v1
kind: Namespace
metadata:
name: frontend
labels:
istio-injection: enabled
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-frontend
namespace: frontend
labels:
app: web-frontend
spec:
replicas: 1
selector:
matchLabels:
app: web-frontend
template:
metadata:
labels:
app: web-frontend
version: v1
spec:
containers:
- image: gcr.io/tetratelabs/web-frontend:1.0.0
imagePullPolicy: Always
name: web
ports:
- containerPort: 8080
env:
- name: CUSTOMER_SERVICE_URL
value: 'http://customers.backend.svc.cluster.local'
---
kind: Service
apiVersion: v1
metadata:
name: web-frontend
namespace: frontend
labels:
app: web-frontend
spec:
selector:
app: web-frontend
type: NodePort
ports:
- port: 80
name: http
targetPort: 8080
我已经通过定义以下 Gateway 和 VirtualService 资源来公开 Web 前端服务,如下所示:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gateway-all-hosts
# namespace: default # Also working
namespace: frontend
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: web-frontend
# namespace: default # Also working
namespace: frontend
spec:
hosts:
- "*"
gateways:
- gateway-all-hosts
http:
- route:
- destination:
host: web-frontend.frontend.svc.cluster.local
port:
number: 80
在后端命名空间中,我有客户 v1 和 v2 部署和相关服务,如下所示:
apiVersion: v1
kind: Namespace
metadata:
name: backend
labels:
istio-injection: enabled
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: customers-v1
namespace: backend
labels:
app: customers
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: customers
version: v1
template:
metadata:
labels:
app: customers
version: v1
spec:
containers:
- image: gcr.io/tetratelabs/customers:1.0.0
imagePullPolicy: Always
name: svc
ports:
- containerPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: customers-v2
namespace: backend
labels:
app: customers
version: v2
spec:
replicas: 1
selector:
matchLabels:
app: customers
version: v2
template:
metadata:
labels:
app: customers
version: v2
spec:
containers:
- image: gcr.io/tetratelabs/customers:2.0.0
imagePullPolicy: Always
name: svc
ports:
- containerPort: 3000
---
kind: Service
apiVersion: v1
metadata:
name: customers
namespace: backend
labels:
app: customers
spec:
selector:
app: customers
type: NodePort
ports:
- port: 80
name: http
targetPort: 3000
我创建了以下 DestinationRule 和 VirtualService 资源,仅将流量发送到 v1 部署。
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: customers
#namespace: default # Not working
#namespace: frontend # working
namespace: backend # working
spec:
host: customers.backend.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: customers
#namespace: default # Not working
#namespace: frontend # working
namespace: backend # working
spec:
hosts:
- "customers.backend.svc.cluster.local"
http:
## route - subset: v1
- route:
- destination:
host: customers.backend.svc.cluster.local
port:
number: 80
subset: v1
-
问题是哪个命名空间适合为客户服务定义 VR 和 DR 资源?
-
从我的测试中,我发现我可以使用前端命名空间或后端命名空间。为什么可以在前端命名空间或后端命名空间中创建 VR、DR 并且在这两种情况下都可以工作?哪个是正确的?
-
DestinationRule 和 VirtualService 资源真的是命名空间资源还是可以被视为集群范围的资源? 无论命名空间如何,代理的低级路由规则是否传播到所有特使代理?
【问题讨论】:
标签: kubernetes istio