kubernetes kubernetes/cka

There are powerful use cases for multi container Pods, including:

  • service meshes
  • Helper services that initialize app environments
  • Apps with tightly coupled helper functions (log scrapers)

Multi-container Pods also help us implement the single responsibility principle(SRP) where every container performs a single simple task.
👉 AF01.1 - SOLID Principles

Example

the main app container might be serving a message queue or some other core application feature. Instead of adding the encryption and telemetry logic into the main app, we keep the app simple and implement it in the service mesh container running alongside it in the same Pod.

👉 05. Docker Containers

apiVersion: v1
kind: Pod
metadata:
  name: simple-webapp
  labels:
    name: simple-webapp
spec:
  containers:
  - name: simple-webapp
    image: simple-webapp
    ports:
    - ContainerPort: 8080
  - name: log-agent
    image: log-agent

Multi Container Pods Design Patterns

Comparison Table

PatternPurposeCommon Use CasesExample
SidecarExtend or enhance functionalityLogging, monitoring, configuration updatesFluentd for log collection, Envoy as a service mesh proxy
AdapterTransform or normalize dataProtocol conversion, metric normalizationConverting metrics to Prometheus format
AmbassadorProxy communication with external systemsAPI gateway, service discovery, TLS terminationEnvoy or HAProxy for routing and load balancing

Sidecar

Secondary container that enhances or extends the functionality of the main application container.

👉 02.Areas/DevOps/0500 - Kubernetes/0550 - K8s-Extras/../../Kubernetes/K8s-Extras/K8s Sidecar Container
👉 Sidecar Pattern & Sidecar Containers

Example:

  • A main container running an application server.
  • A sidecar container running Fluentd to collect and forward logs from the main container.

Adaptor

👀 Adapter

The Adapter pattern involves a secondary container that transforms or normalizes input/output data between the main container and external systems.

  • Protocol Conversion: gRPC —> REST
  • Normalization: Transform raw metrics or logs into a specific format required by external systems.

Example:

  • A main container exposing metrics in a custom format.
  • An adapter container translating the custom metrics into Prometheus-compatible metrics 👉 Observability

Ambassador Pattern

The Ambassador pattern involves a secondary container that acts as an intermediary between the main container and external services.
It abstracts and simplifies communication by handling tasks like authentication, routing, and API requests.

  • API Discovery
  • Service Discovery
  • TLS Termination: The ambassador container terminates SSL/TLS connections before forwarding requests to the main container.

SSL/TLS termination

is the process of decrypting traffic when it enters the network and encrypting traffic when it leaves the network.
A TLS termination proxy used to SSL/TLS termination process.
TLS termination proxy - Wikiwand
What is SSL/TLS termination?

Example:

  • A main container running an application server.
  • An ambassador container running Envoy as a proxy to handle API Init Containersthe main container. 👉 Envoy

05309 [[Init Containersnetes Init Containers A Complete Guide]]
06. Containerizing