我試圖了解與應該定義的命名空間相關的 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
我通過定義以下網關和 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 資源是真正的命名空間資源還是可以被視為集群范圍的資源?無論命名空間如何,代理的低級路由規則是否傳播到所有特使代理?
uj5u.com熱心網友回復:
在請求期間實際應用的 DestinationRule 需要位于目標規則查找路徑上:
-> client namespace
-> service namespace
-> the configured meshconfig.rootNamespace namespace (istio-system by default)
在您的示例中,“web-frontend”客戶端位于前端命名空間(web-frontend.frontend.svc.cluster.local)中,“客戶”服務位于后端命名空間(customers.backend.svc.cluster.local)中,因此customers應在以下命名空間之一中創建 DestinationRule:frontend、backend或istio -系統。此外,請注意不推薦使用istio-system命名空間,除非目標規則確實是適用于所有命名空間的全域配置。
為了確保將應用目標規則,我們可以istioctl proxy-config cluster對web-frontendPod使用以下命令:
$ istioctl proxy-config cluster web-frontend-69d6c79786-vkdv8 -n frontend | grep "customers.backend.svc.cluster.local"
SERVICE FQDN PORT SUBSET DESTINATION RULE
customers.backend.svc.cluster.local 80 - customers.frontend
customers.backend.svc.cluster.local 80 v1 customers.frontend
customers.backend.svc.cluster.local 80 v2 customers.frontend
在默認命名空間中創建目標規則時,它不會在請求期間應用:
$ istioctl proxy-config cluster web-frontend-69d6c79786-vkdv8 -n frontend | grep "customers.backend.svc.cluster.local"
SERVICE FQDN PORT SUBSET DESTINATION RULE
customers.backend.svc.cluster.local 80 -
有關更多資訊,請參閱命名空間檔案中的控制配置共享。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/401722.html
標籤:Kubernetes 伊斯蒂奥
