Skip to main content

Hands-On: Sidecar | Topz (Designing Distributed Systems)

· 2 min read

Sidecar Hands-on Exercise: TOPZ

The purpose of this exercise is to explore the "sidecar" pattern of deploying software using containers and container groups.

This exercise has the reader creating an arbitrary containerised application and a sidecar in the same namespace. The sidecar provides resource monitoring for the virtual host.

The provided instructions use a purpose-built utility called topz, and leaves the main application ambiguous (to be determined by the implementer). The implementation is started using Docker CLI commands.

Below is the exercise as defined in the book's text:

Local Setup

I'm using the default installation of Rancher Desktop (v1.16.0) on Apple M1 Silicon, along with the provided dockerd container engine

Challenges

  1. The author doesn't provide the main application for the exercise

    In the absence of having a specific application to run, on the advice of my code-assistant AI, I've opted to use a standard NGINX container as my base application. This gives me some default behavior for the "main application" that can be observed to verify the setup

  2. The provided image expects a Linux/AMD64 architecture. My code assistant AI has suggested two alternatives:

    1. use an alternate sidecar application (cAdvisor)
    2. Build a Multi-Archtecture Image of Topz

Since this is all practice, I will try both approaches

Solutions

Creating Your Own Multi-Architecture Topz Image

Prequisites

  • Docker Hub account and command-line access
  • A current docker login session

I'm using Rancher Desktop (v1.16.0), configured to use dockerd as the container engine. I'm working on a Macbook Pro with Apple Silicon (M1) running on Mac OS Sonoma 14.6. I'm using Docker Hub as my image repository, under the name iaindavisdotdev.

  1. Activate QEMU for Cross-Platform Builds

  2. Create and Use a Multi-Architecture Builder:

    • Initialize a new Buildx builder for multi-architecture without requiring any experimental flags.

      docker buildx create --name multiarchbuilder --use
      docker buildx inspect --bootstrap
  3. Write a New Dockerfile Create a new Dockerfile to use brendanburns/topz:db0fa58 as the base:

    # Start from the existing topz image
    FROM brendanburns/topz:db0fa58
  4. Build the Multi-Architecture Docker Image:

    • Using brendanburns/topz:db0fa58 as a reference, build your local image. This example skips pushing to a registry:

      docker buildx build --platform linux/amd64,linux/arm64 -t <docker-user>/topz-multiarch:latest --load .

      Screen capture showing newly-created multi-architecture image on Docker Hub

  5. Run the topz Container Locally:

    • Once the build completes, run the container locally:

      docker run -d --name topz-local <docker-user>/topz-multiarch:latest

Reverting Docker/Rancher Desktop to Default Settings

  • If you wish to undo the settings for multi-architecture builds, use the steps below:

    1. Reset Rancher Desktop’s container engine to its original state, if it was modified.

    2. Delete the mybuilder buildx instance (optional):

      docker buildx rm mybuilder

By following these steps, you’ll have a multi-architecture topz image ready to use locally without making global configuration changes.