istio :安装参数之outboundTrafficPolicy.mode

本文介绍了Istio mesh中的outboundTrafficPolicy配置选项,用于管理sidecar如何处理外部服务的访问。默认的ALLOW_ANY模式允许对未知服务的直接访问,而REGISTRY_ONLY则会阻止未在服务注册表中定义的服务。当设置为REGISTRY_ONLY时,需要创建ServiceEntry以允许特定外部服务的访问,例如`httpbin.org`。配置ServiceEntry后,外部服务的访问恢复正常。

背景:

Istio有一个安装选项meshConfig.outboundTrafficPolicy.mode,用于配置外部服务的sidecar处理,即那些未在Istio的内部服务注册表中定义的服务。如果此选项设置为ALLOW_ANY,则Istio代理允许对未知服务的调用通过。如果该选项设置为REGISTRY_ONLY,那么Istio代理将阻止没有在mesh中定义HTTP服务或服务条目的任何主机。ALLOW_ANY是默认值,无需控制对外部服务的访问。
在这里插入图片描述

实验

ALLOW_ANY情况下允许外部服务直接访问

在这里插入图片描述

REGISTRY_ONLY会down掉请求

在这里插入图片描述

此时需要创建serviceentry

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: httpbin-ext
spec:
  hosts:
  - httpbin.org
  ports:
  - number: 80
    name: http
    protocol: HTTP
  resolution: DNS
  location: MESH_EXTERNAL

再次访问服务正常

在这里插入图片描述

根据提供的配置信息,以下是配置中的错误和修改建议: 1. **Service 端口与 VirtualService 端口不匹配**: - 在 `Service` 中,`http` 端口配置为 `8080`,但在 `VirtualService` 中,`destination` 的端口配置为 `80`。 - **修改建议**:将 `VirtualService` 中的 `destination.port.number` 改为 `8080`。 2. **`subnets` 拼写错误**: - 在 `VirtualService` 中,`subnets` 拼写错误,应该是 `subset`。 - 在 `DestinationRule` 中,`subnets` 拼写错误,应该是 `subsets`。 - **修改建议**:将 `VirtualService` 和 `DestinationRule` 中的 `subnets` 改为 `subset` 和 `subsets`。 3. **`DestinationRule` 的 `host` 域名拼写错误**: - 在 `VirtualService` 中,`destination.host` 配置为 `test.test.svc.cluster.lcaol`,拼写错误。 - **修改建议**:将 `test.test.svc.cluster.lcaol` 改为 `test.test.svc.cluster.local`。 4. **`VirtualService` 的 `match` 条件问题**: - 在 `VirtualService` 中,`match` 条件中的 `port` 和 `uri` 组合可能导致路由不匹配。 - **修改建议**:如果只需要匹配 `uri`,可以移除 `port` 条件;或者确保 `port` 与 `Gateway` 的 `port` 一致。 5. **`Service` 的 `selector` 与 `Deployment` 的 `labels` 不完全匹配**: - `Service` 的 `selector` 使用了 `app.kubernetes.io/name: test` 和 `version: 1.1.0`,但 `Deployment` 的 `template.metadata.labels` 使用了 `app.kubernetes.io/name: test` 和 `version: 1.1.0`(注意 `app.kubernetes.io/version` 和 `version` 的区别)。 - **修改建议**:确保 `Service` 和 `Deployment` 的 `selector` 和 `labels` 完全匹配。 ### 修改后的配置建议: ```yaml apiVersion: networking.istio.io/v1beta1 kind: Gateway metadata: name: test-gw namespace: test spec: selector: istio: ingressgateway servers: - hosts: - istio-test.tplinknbu.com port: name: https number: 10143 protocol: HTTPS --- apiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: test-vs namespace: test spec: gateways: - test-gw hosts: - istio-test.tplinknbu.com http: - match: - uri: prefix: /api/v1/ route: - destination: host: test.test.svc.cluster.local port: number: 8080 subset: v1 --- apiVersion: networking.istio.io/v1beta1 kind: DestinationRule metadata: name: test-dr namespace: test spec: host: test.test.svc.cluster.local trafficPolicy: tls: mode: DISABLE subsets: - name: v1 labels: version: 1.1.0 --- apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/name: test name: test-service namespace: test spec: ports: - name: grpc port: 8850 protocol: TCP targetPort: grpc - name: http port: 8080 protocol: TCP targetPort: http selector: app.kubernetes.io/name: test version: 1.1.0 type: ClusterIP --- apiVersion: apps/v1 kind: Deployment metadata: labels: app.kubernetes.io/name: test version: 1.1.0 name: test namespace: test spec: selector: matchLabels: app.kubernetes.io/name: test version: 1.1.0 template: metadata: labels: app.kubernetes.io/name: test version: 1.1.0 spec: containers: - name: test ports: - containerPort: 8850 protocol: TCP - containerPort: 8080 protocol: TCP ``` ### 关键修改点: 1. 修正 `VirtualService` 中的 `destination.port.number` 为 `8080`。 2. 修正 `subnets` 为 `subset` 和 `subsets`。 3. 修正 `test.test.svc.cluster.lcaol` 为 `test.test.svc.cluster.local`。 4. 调整 `VirtualService` 的 `match` 条件,移除 `port` 或确保匹配。 5. 确保 `Service` 和 `Deployment` 的 `selector` 和 `labels` 完全匹配。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值