0

我有一个场景,我需要在不标记命名空间的情况下将 istio-side 注入工作负载。我无法标记命名空间的原因是因为在我的集群中,命名空间是通过自动化过程创建的,并且由于安全原因,目前我无法更改该过程。因此想了解是否有一种方法可以自动将 istio sidecar 注入到工作负载中而无需标记命名空间。

我已经尝试和测试过的资源。

  1. 使用sidecar.istio.io/inject="true"部署/pod 定义中的注释。 Note: the annotation will only work with if the namespace is labelled and for this reason I really don't why do we even have this annotation. For more information please visit: https://github.com/istio/istio/issues/6476#issuecomment-1023817004

  2. 手动注入有效,但它有太多的操作开销,因此不是首选方法。

  3. DiscoverySelector 构造仅适用于命名空间,而不适用于 kubernetes 内的部署/pods 对象。

Istio 版本

client version: 1.12.2
control plane version: 1.12.1
4

1 回答 1

1

上述问题已解决。

实现上述目的的方法是在 pod/deployment 定义中使用sidecar.istio.io/inject="true"as label,而不是作为annotation.

的正确定义应该是这样的

apiVersion: v1
kind: Pod
metadata:
  name: labeled-true
  namespace: policy-disabled
  labels:
    sidecar.istio.io/inject: "true"
spec:
  containers:
  - image: docker.io/citizenstig/httpbin
    imagePullPolicy: IfNotPresent
    name: httpbin

不像这样

apiVersion: v1
kind: Pod
metadata:
  name: labeled-true
  namespace: policy-disabled
  annotations:
    sidecar.istio.io/inject: "true"
spec:
  containers:
  - image: docker.io/citizenstig/httpbin
    imagePullPolicy: IfNotPresent
    name: httpbin
于 2022-02-08T19:26:11.317 回答