CKAD · 25 November 2026 · 8 min read

Kubernetes ambassador pattern: a proxy container on localhost

An ambassador is a proxy container in your app's Pod: the app talks to localhost, the proxy deals with shards, credentials and encryption. How it works, a cache-sharding pair, the Cloud SQL Auth Proxy as a native sidecar, the YAML and when not to use it.

The ambassador pattern puts a proxy container in the same Pod as your app. The app connects to localhost as if its cache or database were running right beside it, and the ambassador, which shares the Pod's network, carries each request to the real servers outside: it picks the right shard, adds encryption, signs in, or retries. The app stays simple, and dealing with the outside world becomes the proxy's job. In Kubernetes you write an ambassador exactly like a sidecar, because that is what it is: a sidecar with one specific job.

TL;DR

  • An ambassador is a proxy container beside the app in one Pod. The app only ever talks to localhost.
  • It works because every container in a Pod shares one network namespace: one IP address, one localhost.
  • The classic case is a sharding proxy in front of a cache. The original example, twemproxy, has had no release since 2021; Envoy's Redis proxy and Meta's mcrouter are the options today.
  • The case you will meet most is a database proxy such as Google's Cloud SQL Auth Proxy, which handles IAM sign-in and encryption for the app.
  • In YAML it is a native sidecar: an entry in initContainers with restartPolicy: Always.
  • Exam: CKAD Application Design and Build (20%), under "multi-container Pod design patterns (e.g. sidecar, init and others)".

This is part 4 of the Kubernetes Pod Patterns series. Part 1 introduces all the patterns; part 3 covers the sidecar that the ambassador is built on.

How the ambassador pattern works

Theme: talking to the outside world

Almost every app depends on something that lives somewhere else: a cache, a database, another team's API. Reaching it is rarely as simple as opening one connection to one address.

Problem: the outside world is complicated

A cache split across three servers needs a client that knows which server holds which key. A managed database wants short-lived credentials and an encrypted connection. A flaky backend needs retries and timeouts. Build all of that into the app and every app, in every language, carries the same client logic, and all of them must change whenever the outside world is rearranged.

Solution: a proxy that the app sees as local

Brendan Burns and David Oppenheimer named the pattern in their 2016 paper Design patterns for container-based distributed systems: ambassador containers "proxy communication to and from a main container". The app programs against what looks like a single server on localhost, and the ambassador holds all the knowledge about where the real servers are and how to reach them. The paper lists three benefits:

  • The developer writes against one simple server, not a cluster.
  • In a test, you can run a real local instance (one cache) in place of the ambassador.
  • The same ambassador image works with apps written in any language.

Put another way, the ambassador presents the app with a simplified view of the outside world. The adapter is its mirror image: it presents the outside world with a simplified view of the app.

The ambassador pattern. On the left, a dotted blue Pod holds two containers: an App box that connects to localhost:6379, and a blue Ambassador proxy container, joined by an arrow labeled localhost. A pill below reads: shared network, one IP, one localhost. On the right, a grey panel labeled Outside the Pod holds Shard 1, Shard 2 and Shard 3, and three arrows fan out from the ambassador to the three shards.

In Kubernetes: essentially a sidecar

"Ambassadors are possible because containers on the same machine share the same localhost network interface," says the paper. A Kubernetes Pod gives you exactly that: every container in a Pod shares the network namespace, including the IP address and ports, so containers reach each other on localhost.

There is no ambassador field in a Pod spec. The Kubernetes docs describe init containers and sidecar containers; "ambassador" appears only in Kubernetes blog posts, never in the docs. So an ambassador is written as a sidecar, and today that means a native sidecar: an entry in spec.initContainers with restartPolicy: Always, on by default since Kubernetes 1.29 and stable since 1.33.

A concrete pair: an app and a sharding proxy

The paper's own example is a cache. The app speaks the memcache protocol to localhost, and a twemproxy ambassador spreads the requests across several memcache servers. Burns's 2015 Kubernetes blog post used Redis instead: an ambassador that sends reads to replicas and writes to the single primary, so the app needs no service discovery at all.

The tools have moved on since then:

  • twemproxy (nutcracker), the paper's proxy for memcached and Redis, is dormant though not archived: its last release, 0.5.0, came out in July 2021, and the last commit was in October 2022.
  • Envoy can act as a Redis proxy, partitioning commands among the instances of a cluster with hash-based partitioning, Ketama distribution, and Redis Cluster support.
  • mcrouter, Meta's memcached protocol router, still gets commits, although its last tagged release is from 2019.
  • Redis Labs' Redis Cluster Proxy says it is not actively maintained and discourages production use. Skip it.

Here is that pair in a real cluster. The app and its proxy are scheduled together in one Pod on one node; the cache shards are ordinary Pods wherever the scheduler put them:

The ambassador pattern in a Kubernetes cluster. On Node 1, a Deployment called orders runs a Pod with one IP address that holds two containers: the orders app, and an ambassador Redis proxy. The app reaches the proxy on localhost:6379. On Node 2 run three cache Pods, cache-0, cache-1 and cache-2, holding shards 1, 2 and 3. Three arrows go from the ambassador to the three cache Pods, labeled: key hash picks a shard.

The real-world one: a database proxy

The ambassador you are most likely to run today is a database proxy. Google's GKE documentation recommends running the Cloud SQL Auth Proxy "in a sidecar pattern": the app connects to 127.0.0.1, and the proxy opens the real connection to Cloud SQL. Google gives three reasons:

  • The app's SQL traffic is not exposed locally: the plain connection never leaves the Pod.
  • There is no single point of failure: each app's access to the database is independent of the others.
  • IAM permissions are granted per application, not to the whole cluster.
A database ambassador. Inside a GKE cluster, a dotted Pod called orders holds an App container whose database host is 127.0.0.1:3306, and a blue Cloud SQL Auth Proxy running as a native sidecar. A grey arrow labeled plain SQL goes from the app to the proxy; a green arrow labeled encrypted and IAM auth goes from the proxy out of the cluster to Cloud SQL, MySQL or PostgreSQL. Three green pills below list the benefits: plain SQL stays in the Pod, no shared proxy to fail, IAM permissions per app.

Google's sample changed with native sidecars: it now puts the proxy under initContainers with restartPolicy: Always, "unless you're using Cloud Service Mesh or Istio", in which case it goes in containers. The project is active; v2.28.1 came out on 23 Nov 2026.

The YAML

A Deployment whose Pods run the app and a Cloud SQL Auth Proxy ambassador. The proxy listens on port 3306 inside the Pod; the app connects to 127.0.0.1:3306:

YAML
apiVersion: apps/v1kind: Deploymentmetadata:  name: ordersspec:  replicas: 2  selector:    matchLabels:      app: orders  template:    metadata:      labels:        app: orders    spec:      serviceAccountName: orders        # the identity given database access in IAM      initContainers:      - name: cloud-sql-proxy           # the ambassador        image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.28.1        restartPolicy: Always           # a native sidecar        args:        - "--structured-logs"        - "--port=3306"        - "my-project:us-central1:orders-db"        securityContext:          runAsNonRoot: true      containers:      - name: orders        image: registry.example.com/orders:1.0        env:        - name: DB_HOST          value: "127.0.0.1"        - name: DB_PORT          value: "3306"

What the native sidecar gives the ambassador:

  • It starts before the app and keeps running for the life of the Pod, restarted whenever it exits.
  • It stops after the app: Kubernetes delays stopping sidecars until the last main container has fully terminated, so the app's last queries still get through.
  • "Starts before" is not "ready before". A readiness probe on the proxy does not make the app wait. If the app must not start until the proxy accepts connections, give the proxy a startupProbe, or let the app retry its first connection.

Check it with kubectl get pods -l app=orders: READY shows 2/2, because native sidecars count. Read the proxy's log with kubectl logs deploy/orders -c cloud-sql-proxy.

When not to use it

  • A library would do. The Kubernetes blog's own advice is that a helper container "is generally not the preferred approach unless the use case justifies it", because it adds complexity, resource use and network latency. If your app has one language and a good client library, use the library.
  • Troubleshooting gets harder. Every failed query now has two suspects, and you must read two containers' logs.
  • A proxy in every Pod. Ten replicas mean ten proxies to size, patch and monitor. That is the price of having no single point of failure.
  • No atomic upgrades. The paper warns that sets of containers "generally can't be upgraded atomically", so you test the app against more than one proxy version.
  • A service mesh already does it. A mesh's sidecar proxy sits on every outbound call and adds mTLS, retries and routing. You can think of it as an ambassador that a control plane injects and configures for you, although neither Kubernetes nor Istio uses that name. Part 6 covers meshes, and why Google's sample moves its proxy for Istio.

For the exam

The CKAD curriculum (v1.37), under Application Design and Build (20%), asks you to "understand multi-container Pod design patterns (e.g. sidecar, init and others)". Up to v1.21 the CKAD named the ambassador outright; from v1.22 it dropped out of the examples and became one of the "others". It is still in scope, but tasks will not say "write an ambassador" so much as "add a second container that the app reaches on localhost".

What you need is the mechanics: two containers in one Pod, the helper as a native sidecar (or in containers if the task shows it there), ports that do not clash because the containers share one IP, and -c <container> on kubectl logs and kubectl exec.

Common questions

What is the difference between an ambassador and a sidecar?

An ambassador is a sidecar with one job: proxying the app's connections to the outside world. Every ambassador is a sidecar; not every sidecar is an ambassador. A log shipper, for example, is a sidecar but proxies nothing.

What is the difference between an ambassador and an adapter?

Direction. The ambassador simplifies the outside world for the app (outbound calls); the adapter simplifies the app for the outside world, for example by turning its metrics into a standard format.

Does the ambassador need its own Service?

No. The app reaches it on localhost, inside the Pod. A Service is only for callers outside the Pod.

Is the ambassador pattern still used?

Yes, though often without the name. The Cloud SQL Auth Proxy is one, and Google's docs now show it as a native sidecar. Service meshes put a similar proxy beside every app automatically.

Keep going

The rest of the series: multi-container Pod patterns (the overview), init containers, sidecar containers, the adapter pattern and service mesh sidecars vs ambient mode.

Patterns stick once you have built them on a real cluster. The Gazeek CKAD course gives you one for every lab, and its Pods and multi-container patterns module puts helpers beside an app with checks that tell you when you have it right. For more exam-style tasks, try the CKAD practice questions with answers.

More from the blog