skip to content
anntz.com

multi-container pods

there might be certain scenarios where we might need to use multiple services together, but also don’t want to combine them making a bloated service altogether.

one of the example of such services that might need this type of design pattern can be:

  • a web server
  • a logging agent

in this case, we will need to scale our logging service based on the traffic in a web server. we can create two containers in a single pod and share the life-cycle and resources such as memory, storage and network space.

creating a multi-container pod is easy as adding the amount of containers in the container array. a simple multi container pod can be something like:

apiVersion: v1
kind: Pod
metadata:
  name: app-server
spec:
  containers:
    - image: ananta/my-packaged-image
      name: my-app-service
    - image: ananta/my-logging-agent
      name: my-logging-agent-service

in this example, we created a simple pod app-server using two container images for a backend service my-app-service and a logging agent my-logging-agent

design pattern

even though creation of multi-container pod is the same, there are various design patterns that we can follow to design a multi-container pod architecture.

  • sidecar patttern
  • adapter pattern
  • ambassador pattern

sidecar pattern

coming back from the previous example, suppose we have a web server and a log agent. The log agent sends log data to another third-party entity/service. This scenario can be called a sidecar pattern because the log agent acts as a child process for the web server to send log data.

adapter pattern

in the adapter pattern, if another process acts as a service to the main process, functioning like an adapter, it is said to be in the adapter pattern. In our example, if the log agent updates data or structure for the central server to process, this is known as the adapter pattern.

ambassador pattern

in the ambassador pattern, if another process acts as a service to the main process, functioning like a proxy for the main service, it is in the ambassador pattern. In our example, if the log agent service keeps track of the database environment (production, sandbox, development) and the main service depends on this service, it is said to be in the ambassador pattern.