Skip to content

Multi-Containers Pod

Container images solve many real-world problems with existing packaging and deployment tools, but in addition to these significant benefits, containers offer us an opportunity to fundamentally re-think the way we build distributed applications. Just as service oriented architectures (SOA) encouraged the decomposition of applications into modular, focused services, containers should encourage the further decomposition of these services into closely cooperating modular containers. By virtue of establishing a boundary, containers enable users to build their services using modular, reusable components, and this in turn leads to services that are more reliable, more scalable and faster to build than applications built from monolithic containers.

Resources

  • Sidecar Logging


    Application logs can help you understand what is happening inside your application.

    Learn more

  • Shared Volume Communication


    Read about how to use a Volume to communicate between two Containers running in the same Pod.

    Learn more

  • Toolkit Patterns


    Read Brendan Burns' blog post about "The Distributed System ToolKit: Patterns for Composite Containers".

    Learn more

  • Brendan Burns Paper


    Read Brendan Burns' paper about design patterns for container-based distributed systems.

    Learn more

References

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  volumes:
    - name: shared-data
      emptyDir: {}
  containers:
    - name: app
      image: bitnami/nginx
      volumeMounts:
        - name: shared-data
          mountPath: /app
      ports:
        - containerPort: 8080
    - name: sidecard
      image: busybox
      volumeMounts:
        - name: shared-data
          mountPath: /pod-data
      command:
        [
          "sh",
          "-c",
          "echo Hello from the side container > /pod-data/index.html && sleep 3600",
        ]
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  shareProcessNamespace: true
  containers:
    - name: app
      image: bitnami/nginx
      ports:
        - containerPort: 8080
    - name: sidecard
      image: busybox
      securityContext:
        capabilities:
          add:
            - SYS_PTRACE
      stdin: true
      tty: true

Attach Pods Together

oc attach -it my-pod -c sidecard
ps ax
kill -HUP 7
ps ax

Attach Pods Together

kubectl attach -it my-pod -c sidecard
ps ax
kill -HUP 7
ps ax

Activities

Task Description Link
Try It Yourself
Multiple Containers Build a container using legacy container image. Multiple Containers