<p>I want to add Consul connect sidecar to kubernetes pods.</p>

<p>I have already installed consul injector in my Consul cluster. I have found this way of adding injection annotation in the documentation:</p>

<pre><code>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
</code></pre>

<p>However, in my K8s cluster there are currently statefull sets and deployments. I have found in the documentation that you cannot annotate deployments.</p>

<p>Has anyone tried establishing consul sidecar envoys with the pods of a deployment/statefull set?</p>

workaround
<p>An example to do it for deployment. You can do it in StatefulSet as well.</p>

<pre><code>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
</code></pre>

<p><a href="https://www.consul.io/docs/platform/k8s/connect.html#deployments-statefulsets-etc-" rel="nofollow noreferrer">https://www.consul.io/docs/platform/k8s/connect.html#deployments-statefulsets-etc-</a></p>
