If you use a Kubernetes cluster and you need to monitor your app’s requests in production, Subtrace is a great fit.

Start by making the following change to your Dockerfile to install Subtrace in your app’s Docker image:

- CMD ["node", "./app.js"]
+ RUN curl -fsSLO https://subtrace.dev/download/latest/$(uname -s)/$(uname -m)/subtrace && chmod +x ./subtrace
+ CMD ["./subtrace", "run", "--", "node", "./app.js"]

Build and push the new Docker image just like you used to before changing your Dockerfile to install Subtrace. Then update your Kubernetes pod spec to point to the new image. Here is an example deployment.yaml for reference:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: ghcr.io/NAMESPACE/IMAGE_NAME:latest
        env:
        - name: SUBTRACE_TOKEN
          valueFrom:
            secretKeyRef:
              name: env-secrets
              key: SUBTRACE_TOKEN
        securityContext:
          capabilities:
            add: ["SYS_PTRACE"]

Make sure the container has the SUBTRACE_TOKEN environment variable in your deployment YAML. Typically, this is done with a Kubernetes secret, but if your app uses an external secret manager, consult its documentation. If you don’t have a Subtrace token yet, go to the Tokens page on the dashboard to create one.

Don’t forget to set the securityContext field in the container spec. Subtrace needs the SYS_PTRACE capability in order to trace your app’s requests.

Finish by applying your changes to the cluster:

kubectl apply -f ./deployment.yaml

And that’s it! Send a HTTP request to the Kubernetes service corresponding to this deployment and you should see it automatically appear in the Subtrace dashboard.