簡體   English   中英

創建自定義 sidecar 並注入 istio 服務網格

[英]create custom sidecar and inject in istio service mesh

我是 Sidecar 和 Istio 世界的新手。 已經閱讀了大約一個星期。 但仍然找不到完美的答案。

首先,是否可以使用 istio 注入自定義 sidecar。 我想要實現的功能是,在請求 header 中,我將收到 2 個令牌(JWT)。 一個用於發行者 (nonce),另一個用於發送者 (pop)。 我需要驗證這兩個令牌是否正確,如果正確,我可以允許他們訪問我的微服務,否則立即拒絕。

所以為了實現這個功能,我創建了一個sidecar,現在我想使用istio來部署它。 但我找不到辦法去做。

我能夠實現的是在我安裝容器后立即發生的自動 sidecar 注入。 但是現在我的結構是,我希望使用 istio 注入自定義邊車。

讓我知道是否有人可以給我一個方向,告訴我我想要實現的目標。 謝謝你。

您可以在 istio 中使用自定義 sidecar 注入模板執行此操作。

例如,要覆蓋默認的 sidecar istio-proxy ,只需在IstioOperator中為模板創建一個覆蓋:

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  name: istio
spec:
  values:
    sidecarInjectorWebhook:
      templates:
        custom: |
          spec:
            containers:
            - name: istio-proxy
              env:
              - name: GREETING
                value: hello-world

這樣,代理將獲得額外的GREETING環境變量。 您還可以注入第二個/不同的自定義邊車。 首先將其添加到IstioOperator清單中:

[...]
  values:
    sidecarInjectorWebhook:
      templates:
        custom: |
          spec:
            containers:
            - name: my-custom-container
              image: my-custom-image

現在,您可以通過使用inject.istio.io/templates注釋對 pod 進行注釋來控制將注入哪個 sidecar。

要替換默認的istio-proxy sidecar,請將其設置為inject.istio.io/templates=custom

要將其作為輔助 sidecar 注入,請將其設置為inject.istio.io/templates=sidecar,custom ,其中sidecar將是默認的 istio sidecar。

您可以檢查istio-system命名空間中的istio-sidecar-injector configmap 以檢查默認配置並驗證您的更改。

有關更多信息,請參閱文檔

請注意,該功能目前仍處於試驗階段。

編輯

這是一個使用第二個 sidecar 的示例部署。 注意 pod 模板中的annotation

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
      annotations: 
        inject.istio.io/templates: sidecar,custom # for custom sidecar
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM