无效选择器
当策略(如 AuthorizationPolicy
、RequestAuthentication
、Telemetry
或 WasmPlugin
)中的工作负载选择器无法有效地定位 Kubernetes 网关中的任何 Pod 时,就会出现此消息。
示例
您将收到类似的消息,例如
Warning [IST0166] (AuthorizationPolicy default/ap-ineffective testdata/k8sgateway-selector.yaml:47) Ineffective selector on
Kubernetes Gateway bookinfo-gateway. Use the TargetRef field instead.
当您的策略的选择器匹配 Kubernetes 网关时。
例如,当您有一个 Kubernetes 网关 Pod,例如
apiVersion: v1
kind: Pod
metadata:
annotations:
istio.io/rev: default
labels:
gateway.networking.k8s.io/gateway-name: bookinfo-gateway
name: bookinfo-gateway-istio-6ff4cf9645-xbqmc
namespace: default
spec:
containers:
- image: proxyv2:1.21.0
name: istio-proxy
并且存在一个带有 selector
的 AuthorizationPolicy
,例如
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
namespace: default
name: ap-ineffective
spec:
selector:
matchLabels:
gateway.networking.k8s.io/gateway-name: bookinfo-gateway
action: DENY
rules:
- from:
- source:
namespaces: ["dev"]
to:
- operation:
methods: ["POST"]
如果您在策略中同时具有 targetRef
和 selector
,则不会出现此消息。例如
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
name: telemetry-example
namespace: default
spec:
tracing:
- randomSamplingPercentage: 10.00
selector:
matchLabels:
gateway.networking.k8s.io/gateway-name: bookinfo-gateway
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: bookinfo-gateway
如何解决
确保您正在将 selector
字段用于 Sidecar 或 Istio 网关 Pod,并将 targetRef
字段用于 Kubernetes 网关 Pod。否则,策略将不会应用。
以下是一个示例
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
name: telemetry-example
namespace: default
spec:
tracing:
- randomSamplingPercentage: 10.00
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: bookinfo-gateway