Medium java docker

What is a sidecar container, and when do you use one?

The 30 second answer

A sidecar is a helper container in the same Kubernetes Pod as the application container. It shares the network namespace (and often volumes) with the app, so it can proxy traffic, ship logs, or rotate certificates without the application embedding that code. I use one when the helper must be scheduled and scaled with the app process; I do not use one for a service that should scale independently.

Could you say this in an interview?

In Kubernetes, a Pod can run more than one container. The extra containers that assist the main one are commonly called sidecars. They share the Pod IP and can share volumes. Kubernetes documents this multi-container Pod model; a Service still targets the Pod, not an individual container.

Typical uses: a service-mesh proxy (Envoy), a log or metrics agent that tails a shared volume, or a process that mints TLS certificates and writes them to a volume the app reads. The lifecycle is the point: the helper starts, restarts and dies with the app.

What it is not: a second microservice. If the helper needs its own scaling, its own Service, or a different release cadence, it should be a separate Deployment.

apiVersion: v1
kind: Pod
metadata:
  name: checkout
spec:
  containers:
    - name: app
      image: registry.example/checkout:1.4.2
      ports: [{containerPort: 8080}]
    - name: access-logs
      image: registry.example/log-shipper:2
      volumeMounts:
        - name: logs
          mountPath: /var/log/app
      # the shipper tails the same volume the app writes
  volumes:
    - name: logs
      emptyDir: {}
Sources (2)
  1. Kubernetes: Pods (multi-container pods)kubernetes.io
  2. Kubernetes: Sidecar containerskubernetes.io