Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 36 ยท Resilience and Policies

Istio Sidecar Resource: Scoping Config and Tuning Proxies

Shrink Envoy configuration and memory in large meshes with the Sidecar resource, set proxy CPU and memory, tune concurrency, startup and graceful shutdown for production workloads.

By default, istiod gives every sidecar the configuration for every service in the mesh. With 20 services this is harmless. With 2,000 services, each of thousands of proxies receives and stores a huge configuration, spends memory on it and gets a new push whenever any service anywhere changes. Memory, CPU and control plane load grow with the square of the mesh size. The fix is to tell each proxy which services it actually needs.

The product cannot run on this site, so configuration is read-only and the Python stand-ins estimate the effect.

The Sidecar resource

The Sidecar custom resource (not to be confused with the proxy container) limits what a workload's proxy knows and how it accepts traffic.

YAML
apiVersion: networking.istio.io/v1
kind: Sidecar
metadata:
  name: default
  namespace: shop                 # applies to the whole namespace when no workloadSelector is set
spec:
  egress:
    - hosts:
        - "./*"                   # all services in this namespace
        - "istio-system/*"        # control plane and gateways
        - "payments/payments-api.payments.svc.cluster.local"

The hosts entries use the format namespace/host: ./* means the same namespace, */* everything. With this resource the proxy in shop receives configuration only for its own namespace, istio-system and one named service. A call to anything else fails (or is passed through, depending on the outbound traffic policy), so the list must be accurate.

A mesh-wide default can be placed in the root namespace (istio-system) with a conservative list, and teams can override it in their namespaces. A workloadSelector narrows a Sidecar to specific pods.

Other useful settings:

YAML
spec:
  workloadSelector:
    labels:
      app: reviews
  ingress:
    - port: { number: 9080, protocol: HTTP, name: http }
      defaultEndpoint: 127.0.0.1:9080
  outboundTrafficPolicy:
    mode: REGISTRY_ONLY

Use istioctl proxy-config clusters <pod> before and after to see how many clusters the proxy holds.

Proxy resources

Each sidecar needs CPU and memory. Defaults request small values, and you should set them to measured needs. Per-pod annotations override the mesh defaults:

YAML
metadata:
  annotations:
    sidecar.istio.io/proxyCPU: "100m"
    sidecar.istio.io/proxyMemory: "128Mi"
    sidecar.istio.io/proxyCPULimit: "500m"
    sidecar.istio.io/proxyMemoryLimit: "256Mi"
    proxy.istio.io/config: |
      concurrency: 2

concurrency is the number of Envoy worker threads. Left at default, Envoy sizes itself from the CPU limit of the container; setting it explicitly to the CPU limit rounded up avoids creating many idle threads, a classic source of wasted memory on large nodes.

Startup and shutdown

Two lifecycle problems occur in almost every mesh:

  1. The application starts before the proxy is ready. Early outbound calls fail because the sidecar cannot yet route them. Set holdApplicationUntilProxyStarts: true in the mesh proxy config (or via the pod annotation proxy.istio.io/config). The application container then starts only after the proxy is ready. Recent Kubernetes versions with native sidecar containers handle this ordering natively when enabled in Istio.
  2. The proxy dies before the application finishes. During a rolling update the proxy must stay alive long enough for in-flight requests and the application's own shutdown work. Tune terminationDrainDuration (default 5 seconds) and, where your Istio version supports it, EXIT_ON_ZERO_ACTIVE_CONNECTIONS, so the proxy exits when no connections remain.

For jobs, the proxy container used to keep a Kubernetes Job from completing. Native sidecars solve this; otherwise the job should call the proxy's quit endpoint (curl -X POST localhost:15000/quitquitquit) at the end.

Scale of the problem

Config size per proxy grows with the number of services, endpoints and routes it receives. Without scoping it is the whole mesh; with scoping it is the part the pod uses. Control plane work grows with proxies times the update rate, so scoping also reduces push load and the time proxies need to converge after a change.

Try it: estimate config size with and without a Sidecar

This stand-in uses a made-up cost of 1,000 bytes per service per proxy and a typical dependency of 15 services, to show the shape of the curve, not exact numbers.

Python Mesh size versus proxy configuration

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Try it: derive a Sidecar from a dependency list

If you know (from traces, metrics or Kiali) which services a workload calls, you can generate its Sidecar resource.

Python Generate a Sidecar egress list

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Generated lists are a starting point: add rarely used dependencies (batch jobs, failover targets) by hand and review before applying.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a Sidecar resource with egress hosts ['./*'] do?

    ./* means the same namespace, so the proxy no longer receives the rest of the mesh configuration.
  2. 2. Why does scoping help the control plane?

    Proxies only receive updates for what they import.
  3. 3. What problem does holdApplicationUntilProxyStarts solve?

    It delays the application container until the proxy can route traffic.
  4. 4. What does the proxy concurrency setting control?

    Concurrency sets worker threads; matching it to the CPU limit avoids idle threads.

Summary

  • Without scoping, every proxy holds the whole mesh configuration; cost grows quickly with mesh size.
  • The Sidecar resource limits egress hosts (and shapes ingress) per namespace or workload.
  • Set proxy CPU, memory and concurrency from measurements.
  • Handle startup order and graceful drain explicitly.

Next: Canary upgrades with revisions