Skip to main content
Sidecars are containers that run alongside the Steps in your Task, providing supporting services like databases, Docker daemons, or SSH servers. This guide shows you how to use sidecars effectively.

Overview

Sidecars enable you to:
  • Run services that Steps need to communicate with
  • Provide test dependencies like databases or message queues
  • Run Docker-in-Docker for building container images
  • Set up SSH servers or other network services
  • Share resources with Steps through volumes
Sidecars start before Steps execute and run throughout the Task execution.

Basic Sidecar Configuration

Define sidecars in the Task specification:

Docker-in-Docker Sidecar

A common use case is running Docker commands from Steps:
Docker-in-Docker requires privileged mode. Ensure your cluster security policies allow privileged containers.

Sharing Data with Volumes

Sidecars and Steps can share data through volumes:

Sidecar Readiness

Use readiness probes to ensure sidecars are ready before Steps start:
Steps wait for sidecars with readiness probes to become ready before executing.

Startup Probes

Use startup probes for sidecars that need extra time to initialize:

SSH Server Sidecar

Run an SSH server for Git operations:

Workspaces in Sidecars

Sidecars can access Task workspaces:

Variable Substitution in Sidecars

Sidecars support variable substitution:
Supported fields:
  • spec.sidecars[].name
  • spec.sidecars[].image
  • spec.sidecars[].imagePullPolicy
  • spec.sidecars[].env.value
  • spec.sidecars[].command
  • spec.sidecars[].args
  • spec.sidecars[].script
  • spec.sidecars[].volumeMounts

Sidecar Lifecycle

Startup Order

  1. Sidecars start first
  2. Sidecars with readiness probes must become ready
  3. Steps execute in order
  4. Sidecars continue running during Step execution

Shutdown

Sidecars automatically stop when:
  • All Steps complete successfully
  • A Step fails and the Task stops
  • The TaskRun times out
Tekton sends a SIGTERM to sidecars to request graceful shutdown. If sidecars don’t exit within the grace period, they receive SIGKILL.

Resource Management

Specify resource requests and limits for sidecars:

Best Practices

Use Readiness Probes

Always configure readiness probes for sidecars that Steps depend on. This prevents race conditions where Steps try to connect before the sidecar is ready.

Minimize Sidecar Size

Share Data via Volumes

Use volumes instead of network communication when possible:

Set Security Contexts

Common Patterns

Database for Testing

Service Mesh Proxy

Message Queue

Check these common issues:
  1. Image pull errors: Verify the image exists and is accessible
  2. Resource constraints: Ensure the cluster has sufficient resources
  3. Security policies: Check if security contexts or policies block the sidecar
  4. Volume mount conflicts: Verify volume mounts don’t conflict with Step mounts
View sidecar logs:
Steps communicate with sidecars via:
  1. Localhost networking: Sidecars listen on localhost or 127.0.0.1
  2. Shared volumes: Exchange files through mounted volumes
  3. Environment variables: Pass configuration via env vars
Example: