loading...
Cover image for Kubernetes Patterns : The Ambassador Pattern

Kubernetes Patterns : The Ambassador Pattern

ahmedat71538826 profile image Ahmed Atef Originally published at magalix.com ・1 min read

Kubernetes Patterns (8 Part Series)

1) Kubernetes Patterns : The DaemonService Pattern 2) Kubernetes Patterns : The Stateful Service Pattern 3 ... 6 3) Kubernetes Patterns : The Stateful Service Pattern 4) Kubernetes Patterns : The Stateful Service Pattern 5) Kubernetes Patterns : The Cron Job Pattern 6) Kubernetes Patterns - The Batch Job Pattern 7) Kubernetes Patterns : The Reflection Pattern 8) Kubernetes Patterns : The Ambassador Pattern

What is an Ambassador container?
An Ambassador container is a sidecar container that is in charge of proxying connections from the application container to other services. However, while the Adapter container acts as a reverse proxy, the Ambassador container acts as a client proxy. You might be wondering, why do we need to proxy the application connection requests? Because we need to follow the separation of concerns principle. Each container should do it’s task and do it well. If there are other tasks that requires the application’s function in order to work correctly, we may hand those tasks to the sidecar container.

For example, almost all applications need a database connection at some phase. In a multi-environment place, there would be a test database, a staging database, and a production database. When writing the Pod definition for their application’s container, developers must pay attention to which database they’ll be connecting to. A database connection string can be easily changed through an environment variable or a configMap. We could also use a sidecar pattern that proxies DB connections to the appropriate server depending on where it runs. Developers needn’t change the connection string, they could leave the DB server at localhost as usual. When deployed to a different environment, the Ambassador container detects which environment it is running on (possibly through the Reflection pattern), and connects to the correct server.

Another well-known use case for the Ambassador container is when your application needs to connect to a caching server like Memcached or Redis. Let’s have a Redis example scenario to demonstrate this pattern.

Kubernetes Patterns (8 Part Series)

1) Kubernetes Patterns : The DaemonService Pattern 2) Kubernetes Patterns : The Stateful Service Pattern 3 ... 6 3) Kubernetes Patterns : The Stateful Service Pattern 4) Kubernetes Patterns : The Stateful Service Pattern 5) Kubernetes Patterns : The Cron Job Pattern 6) Kubernetes Patterns - The Batch Job Pattern 7) Kubernetes Patterns : The Reflection Pattern 8) Kubernetes Patterns : The Ambassador Pattern

Posted on Oct 31 '19 by:

Discussion

markdown guide