将 consul connect sidecar 添加到 kubernetes helm 部署的 pods

Add consul connect sidecar to pods of a kubernetes helm deployment

我想将 Consul connect sidecar 添加到 kubernetes pods。

我已经在我的 Consul 集群中安装了 consul injector。我在文档中找到了这种添加注入注解的方式:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: static-server
---
apiVersion: v1
kind: Pod
metadata:
  name: static-server
  annotations:
    "consul.hashicorp.com/connect-inject": "true"
spec:
  containers:
    # This name will be the service name in Consul.
    - name: static-server
      image: hashicorp/http-echo:latest
      args:
        - -text="hello world"
        - -listen=:8080
      ports:
        - containerPort: 8080
          name: http
   # If ACLs are enabled, the serviceAccountName must match the Consul service name.
  serviceAccountName: static-server

但是,在我的 K8s 集群中,当前存在有状态集和部署。我在文档中发现您无法注释部署。

有没有人试过用 deployment/statefull 集合中的 pods 来建立 consul sidecar 特使?

用于部署的示例。你也可以在 StatefulSet 中实现。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: consul-example-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: consul-example
  template:
    metadata:
      labels:
        app: consul-example
      annotations:
        "consul.hashicorp.com/connect-inject": "true"
    spec:
      containers:
        - name: consul-example
          image: "nginx"
      serviceAccountName: consul-example

https://www.consul.io/docs/platform/k8s/connect.html#deployments-statefulsets-etc-