Orchestrate containers

Open in ClaudeOpen in ChatGPT

You are free to choose any orchestrator to manage the containers running the ZED SDK.

Below are examples for two popular orchestrators: Docker Compose and Kubernetes.

Docker Compose

Docker Compose is quick to set up. You just need to make sure that every Docker runtime parameter mentioned in the rest of this documentation is also present in your docker-compose.yaml file:

  • The privileged mode.
  • The nvidia runtime.
  • The NVIDIA_DRIVER_CAPABILITIES environment variable.
  • The shared volumes.

The runtime: nvidia key requires the Compose file format 2.3 (or 2.4), which is why the examples below use that version.

Once you have completed the setup, you are ready to go. You can try it out with the example service we provide.

USB camera example
1version: '2.3'
2services:
3 your_app:
4 image: <your-image>
5 runtime: nvidia
6 environment:
7 - NVIDIA_DRIVER_CAPABILITIES=all
8 privileged: true
9 volumes:
10 - /usr/local/zed/resources:/usr/local/zed/resources
11 - /usr/local/zed/settings:/usr/local/zed/settings
12 - /dev:/dev
GMSL2 camera example (ZED X, ZED X One)
1version: '2.3'
2services:
3 your_app:
4 image: <your-image>
5 runtime: nvidia
6 environment:
7 - NVIDIA_DRIVER_CAPABILITIES=all
8 privileged: true
9 volumes:
10 - /usr/local/zed/resources:/usr/local/zed/resources
11 - /usr/local/zed/settings:/usr/local/zed/settings
12 - /var/nvidia/nvcam/settings/:/var/nvidia/nvcam/settings/
13 - /etc/systemd/system/zed_x_daemon.service:/etc/systemd/system/zed_x_daemon.service
14 - /tmp/:/tmp/
15 - /dev:/dev

Kubernetes

To use Kubernetes, we recommend setting up a cluster with k3s. Adding NVIDIA® Container Runtime support to k3s takes a few steps, described here.

  • Make sure the NVIDIA container runtime is properly installed. You can check it in the /etc/docker/daemon.json file:
1{
2 "default-runtime": "nvidia",
3 "runtimes": {
4 "nvidia": {
5 "args": [],
6 "path": "nvidia-container-runtime"
7 }
8 }
9}
  • Add a RuntimeClass to your Kubernetes configuration:
1apiVersion: node.k8s.io/v1
2kind: RuntimeClass
3metadata:
4 name: nvidia
5handler: nvidia
  • Reference the runtime class in the target pod:
1spec:
2 runtimeClassName: nvidia
  • You may also need to install the NVIDIA device plugin in your cluster (check the k8s-device-plugin repository for the latest release): sudo k3s kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.14.1/nvidia-device-plugin.yml

Once you have completed the setup, you are ready to go. You can try it out with the example pod we provide.

Example pod configuration file for USB cameras
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: zed-sample
5spec:
6 replicas: 1
7 selector:
8 matchLabels:
9 app: your-app
10 template:
11 metadata:
12 labels:
13 app: your-app
14 spec:
15 containers:
16 - name: your-container
17 image: <your_image>
18 securityContext:
19 privileged: true
20 env:
21 - name: NVIDIA_DRIVER_CAPABILITIES
22 value: "all"
23 volumeMounts:
24 - name: dev
25 mountPath: dev
26
27 command: ["tail", "-f", "/dev/null"]
28 resources:
29 limits:
30 nvidia.com/gpu: 1 # Assuming you want to allocate one GPU
31 requests:
32 nvidia.com/gpu: '1'
33 volumes:
34 - name: dev
35 hostPath:
36 path: /dev

For GMSL2 cameras, add the same additional shared volumes as before.