The ambassador pattern
An ambassador is a proxy container in the app's Pod; the app talks to localhost and the proxy picks shards, signs in and encrypts. How it works, a cache-sharding pair, the Cloud SQL Auth Proxy as a native sidecar in YAML, and when not to use one.
Now try it on a real cluster
The videos are free. Gazeek's hands-on labs give you a real Kubernetes cluster in your browser for every lab, with checks that tell you when you've got it right: the practice the CKA and CKAD exams need.
The diagrams, full size
Copy any of them into archhy, free, and change it for your own system.
- Drawing the picture…
D1How an ambassador worksAt 0:45 · Copy and edit in archhy (opens in a new tab) - Drawing the picture…
D2A concrete pair: app and cache proxyAt 1:31 · Copy and edit in archhy (opens in a new tab) - Drawing the picture…
D3The one you'll meet: a database proxyAt 1:56 · Copy and edit in archhy (opens in a new tab)
After this lesson you can
- Explain what an ambassador container does and why localhost reaches it
- Describe a sharding proxy beside an app
- Describe the Cloud SQL Auth Proxy as a native sidecar
- Weigh an ambassador against a library or a service mesh
Transcript
The ambassador pattern
Space Llama here. Every embassy needs an ambassador, someone who knows the locals so you don't have to. Today, the ambassador pattern: a proxy container that deals with the outside world for your app.
The outside world is complicated
Almost every app depends on something elsewhere: a cache, a database, another team's API. A cache split across three servers needs a client that knows which server holds each key. A managed database wants short-lived credentials and encryption. Build that into every app, in every language, and they all change whenever the outside world moves. The ambassador moves it into a proxy beside the app. In the paper's words, it proxies communication to and from a main container.
How an ambassador works
Here's the pattern. On the left, a Pod with the app and its ambassador. On the right, three cache shards outside the Pod. The app talks to localhost, port 6379, as if a single cache ran right beside it. One simple connection. That works because both containers are in the same Pod. They share its IP address, so localhost reaches the proxy. The ambassador hashes each key, picks the shard that holds it, and forwards the request. The outside world can change. Add or move a shard, and you change the proxy's configuration, not the app. And testing gets easier. In a test, run one real cache on localhost instead of the ambassador.
A concrete pair: app and cache proxy
Here's that pair in a real cluster. The orders app and its Redis proxy share a Pod on node one. The cache Pods run wherever the scheduler put them. The paper's original proxy was twemproxy. It's dormant now: its last release came out in 2021. Today, Envoy can act as a Redis proxy, partitioning commands across a cluster. For memcached, there's Meta's mcrouter.
The one you'll meet: a database proxy
The ambassador you'll most likely run is a database proxy, like Google's Cloud SQL Auth Proxy. The docs for GKE, Google Kubernetes Engine, recommend running it in a sidecar pattern. The app connects to 127.0.0.1, and the proxy opens the real connection. Three reasons: plain SQL stays in the Pod, there's no shared proxy to fail, and Identity and Access Management permissions are granted per app.
The proxy, line by line
Here's the YAML: the Pod template from inside a Deployment called orders. The service account is the Pod's identity. It's the one given access to the database. The proxy sits in the init containers list, not in containers. Restart policy Always makes it a native sidecar. It starts before the app, and stops after it, so the app's last queries still get through. Its arguments set the port to listen on, 3306, and name the database to connect to. The app goes in containers, and its settings point at 127.0.0.1, port 3306. That's the proxy, right beside it. One catch: starting first isn't being ready first. Give the proxy a startup probe, or let the app retry its first connection.
When not to use one
When not to use one? If your app has one language and a good client library, use the library. Troubleshooting gets harder: every failed query has two suspects. And ten replicas mean ten proxies to size, patch and monitor. A service mesh puts a similar proxy on every outbound call. That's our comparison, not Istio's name for it. Episode six covers meshes.
For the CKAD
For the CKAD, the Certified Kubernetes Application Developer exam, the ambassador was named outright up to version 1.21. Now it's one of the others. A task will rarely say write an ambassador. It'll say add a second container the app reaches on localhost. Watch the ports: both share one IP address.
Remember
Let's recap. The app only ever talks to localhost. The ambassador picks shards, signs in and encrypts. In the YAML, it's just a sidecar with one job. And the one you'll meet most is a database proxy.
Practice and what's next
The full article, with the YAML, is on the Gazeek blog. Read more from the link below. Try the patterns on your own in the lab in Gazeek Labs, and test yourself with the practice questions. Next episode: the adapter pattern, the ambassador's mirror image. See you there.
Hands-on labs
Now try it on a real cluster
Pod patterns on your own: a real cluster built for you, checked as you go.
Open the labGazeek Flash · free
Exam questions on your phone
Free questions on Application Design and Build: quick-fire batches and timed exams, on the web or Android.




