Guides
Advanced
Sidecar Containers

Using Sidecar Containers with Flightcontrol

Flightcontrol allows you to add a sidecar container to your Web Server or Worker containers to perform additional tasks. For example, you can add a sidecar container to your Web Server container to send metrics to a metrics aggregation service.

With Flightcontrol, you will need to be using the flightcontrol.json file to define your environment. If you use the dashboard to create your environment, you can contact support to eject your environment to a flightcontrol.json file..

What is a Sidecar Container?

A sidecar container is a container that runs alongside your main container. You decide how much of the CPU and memory get allocated between the main container and any sidecar container(s).

Typically, sidecar containers come from a third-party provider. For example, you might use a sidecar container to send metrics to a service like Datadog (opens in a new tab). The vendor would provide the URL to an image that you can use to create the sidecar container. You can see an example of adding Datadog as a sidecar here.

Adding a Sidecar Container

Start with a Flightcontrol environment that contains a Web Service or Worker service. You can add a sidecar container to either of these services.

To add a sidecar container, add a sidecars array to your service definition. Each object in the array defines a sidecar container. The following properties are available:

  • name - The name of the sidecar container.
  • image - The URL to the image for the sidecar container.
  • cpuAllotment - The absolute amount of CPU to allocate to the sidecar container. In vCPU units. For example, 0.25 would be 1/4 of a vCPU.
  • memoryAllotment - The absolute amount of memory to allocate to the sidecar container. In GB units. For example, 0.5 would be 1/2 of a GB.
  • enableNetworking - Whether to enable networking for the sidecar container. Defaults to true.
  • ports - An array of ports to expose from the sidecar container. Defaults to [].
  • envVariables - An object of environment variables to set in the sidecar container. Defaults to {}. You can use the same rules for environment variables as you would for your main container.
  • dockerLabels - An object of Docker labels to set in the sidecar container. Defaults to {}.

The name, image, cpuAllotment, and memoryAllotment properties are required. The other properties are optional.

Example: Sidecar Container for AWS's OpenTelemetry Collector

The following example adds a sidecar container to a Web Service:

{
  "$schema": "https://app.flightcontrol.dev/schema.json",
  "environments": [
    {
      "id": "production",
      "name": "Production",
      "region": "us-east-2",
      "source": {
        "branch": "main"
      },
      "services": [
        {
          "id": "my-webapp",
          "name": "My Webapp",
          "type": "web",
          "target": {"type": "fargate"},
          "buildType": "nixpacks",
          "cpu": 0.5,
          "memory": 1,
          "minInstances": 1,
          "maxInstances": 1,
          "sidecars": [
            {
              "image": "public.ecr.aws/aws-observability/aws-otel-collector:latest",
              "name": "aws-otel-collector",
              "memoryAllotment": 0.25,
              "cpuAllotment": 0.25,
              "envVariables": {
                "AOT_CONFIG_CONTENT": {
                  "fromParameterStore": "otel-config" // Its value holds the config file.
                }
              },
              "ports": [4317, 4318]
            }
          ]
        }
      ]
    }
  ]
}

For more information on AWS's OpenTelemetry Collector see their docs (opens in a new tab).

Viewing Logs for a Sidecar Container

After you add a sidecar container, Flightcontrol will deploy your environment. The sidecar container will be deployed alongside your main container. The runtime logs for the sidecar container will be available in the Cloudwatch logs that you can view with the Runtime Logs button in the dashboard.

The log group will be prefixed with the name of the sidecar container in the flightcontrol.json file.

For example, if you open the Runtime Logs to visit AWS Cloudwatch, you will see something similar to the following screenshot:

AWS Cloudwatch Logs with Open Telemetry Collector highlighted

You can see that the log group is prefixed with the name of the sidecar container, open-telemetry-collector. You can click on the log group to view the logs for the sidecar container.

Troubleshooting

If you have any questions about using sidecar containers with Flightcontrol, contact support.