#How to run a dagger pipeline written in the GO SDK in a K8s Pod?

1 messages · Page 1 of 1 (latest)

graceful pebble
#

I love dagger. Have even made a YouTube video on the previous version. I'm planning to cover the new sdk (go and GraphQL) in my next video.

Just one question... How to run a dagger pipeline written in go on Kubernetes... In a pod.

tender cradle
graceful pebble
#

That seems like a bit of an anti-pattern in Kubernetes.

Ideally i would want a runner and executor kinda a setup where we have the dagger daemon (runner) running as a long lived process. The runner would spin up Kubernetes jobs to run the steps

tender cradle
graceful pebble
obsidian forge
# tender cradle 👋 here's some brief information about it: https://github.com/dagger/dagger/blob...

I have the Dagger engine running in my cluster and I am using the _EXPERIMENTAL_DAGGER_RUNNER_HOST env var on my workstation to run the Dagger CLI. So far so good...

Now I would like to create a pod that can run a Dagger AI agent (aka a Dagger module written in Go) but I am not sure how to do that. I am thinking that for the POD's image I would create a custom image that has the Dagger CLI and Kubeclt installed as well as a copy of my module sourc, then I would call dagger run as the pod's startup command. And since the pod is running in the same cluster as the "agent" I would be sure to set _EXPERIMENTAL_DAGGER_RUNNER_HOST environment variable, also this is why I think kubectl is needed.

Does that sound right? If so is there an existing container image for this or do I have to create it?

tender cradle
#

The helm chart puts the Dagger engine Unix socket in a volume by default. If you create a pod with the Dagger CLI and set the _EXPERIMENTAL_DAGGER_RUNNER_HOST to unix:///$sockpath that will make it work

#

So no kubectl is needed

#

@obsidian forge

obsidian forge
#

Awesome, I will give that a try and report back, thanks

obsidian forge
#

Quick followup question. I plan to run the Dagger CLI in a separate POD from the Engine so I am unclear where it will get the value for the env var $socketpath for "unix:///$sockpath", what am I missing? Also I don't I need to mount a shared volume to use a socket?

In the engine pod I see the following but no volume

  containers:
  - args:
    - --addr
    - tcp://0.0.0.0:8080
    - --addr
    - unix:///run/dagger/engine.sock
#

I found the hostPath that is set by the Engine. I guess I need to make sure my pod is on the same host and mount that same host path. I will give that a try untill I hear otherwise...

obsidian forge
#

Good news that worked, I was able to connect the Dagger CLI to the Dagger Enginve via a socket. Here is my Deployment manifest if others are interested:

As a test I shelled into the pod, manually installed the Dagger CLI and then ran the dagger shell, it works!

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: sre-ai-agent
  name: sre-ai-agent
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sre-ai-agent
  template:
    metadata:
      labels:
        app: sre-ai-agent
    spec:
      serviceAccountName: sre-ai-agent
      containers:
      - name: main
        image: ubuntu:latest 
        command:
        - /bin/bash
        - -c
        - | 
          while true; do 
            date; echo 'ZZZzzz..'; sleep 1m; 
          done
        env:
        - name: "_EXPERIMENTAL_DAGGER_RUNNER_HOST"
          value: "unix:///run/dagger/engine.sock"
        volumeMounts:
        - name: dagger-engine-socket
          mountPath: /run/dagger
      volumes:
        - name: dagger-engine-socket
          hostPath:
            path: /run/dagger-dagger
            type: ""