ai-gateway

by JiHu(GitLab)

Helm chartv19.6.0App self-hosted-v19.6.0-jh

A Helm chart for Kubernetes

About this chart

ai-gateway-helm-chart

:warning: This helm chart is meant for self-hosted models users only!

For all other purposes please consider using Runway.

Installation

To install the Helm chart using self-hosted models,

helm repo add ai-gateway \
  https://gitlab.com/api/v4/projects/gitlab-org%2fcharts%2fai-gateway-helm-chart/packages/helm/devel

helm repo update

helm upgrade --install ai-gateway \
  ai-gateway/ai-gateway \
  --version 0.8.1 \
  --namespace=ai-gateway \
  --create-namespace \

On a new install, set legacyService.enabled: false. The chart then serves the API on <fullname>-api and the Duo Workflow Service on <fullname>-duo-workflow, where <fullname> is ai-gateway for the command above. In the GitLab Duo admin settings, set the Local AI Gateway URL to http://<fullname>-api.<namespace>.svc and the Local URL for the GitLab Duo Agent Platform service to <fullname>-duo-workflow.<namespace>.svc:50052. With grpc-tls-proxy.enabled: true, set grpc-tls-proxy.upstream.host to <fullname>-duo-workflow. With tls.secretName, use https:// in the Local AI Gateway URL, select Use TLS for the GitLab Duo Agent Platform service, and use a certificate that covers both names with their .<namespace>.svc forms.

Upgrading

<fullname> below is the name of the chart's existing Service, for example ai-gateway for a release named ai-gateway.

0.16.0: Duo Workflow Service in its own Deployment

From 0.16.0 the Duo Workflow Service runs in its own Deployment, beside the AI Gateway API, and each has its own Service: <fullname>-api for the API and <fullname>-duo-workflow on port 50052.

The existing <fullname> Service is deprecated, and is removed in 0.17.0. Until then its ports and selector are unchanged, the API pod still runs the Duo Workflow Service behind it, and the chart's Ingresses and routes keep using it, so the upgrade to 0.16.0 needs no manual step apart from the LoadBalancer and anti-affinity cases below. Traffic through <fullname> still reaches the Duo Workflow Service inside the API pod, where nothing restarts it if it exits. Its own Deployment does, so clients get that once they use <fullname>-duo-workflow.

With service.type: LoadBalancer, the two new Services get load balancers of their own, which carry no traffic until clients move. They also take service.annotations, so if an annotation pins an address that <fullname> already holds, the new Services stay Pending and helm upgrade --wait or --atomic times out. Without --wait and --atomic the upgrade completes, and <fullname> keeps its address and keeps serving.

After the upgrade:

  • The Duo Workflow Service pods use duoWorkflow.resources, or the top-level resources when it is not set.
  • They run duoWorkflow.replicaCount replicas, or replicaCount when it is unset or 0. To run none, set duoWorkflow.enabled: false.
  • They carry app.kubernetes.io/name: <name>-duo-workflow, so update any NetworkPolicy, PodMonitor, or anti-affinity rule that selects them by the old name.
  • They also take the top-level affinity. A required pod anti-affinity rule on app.kubernetes.io/name: <name> keeps them off every node that runs an API pod, so with as many API replicas as nodes they stay Pending. As preferredDuringSchedulingIgnoredDuringExecution, the same rule lets them schedule beside the API pods, and it is then only a preference for the API pods too.

0.17.0: combined Service removed

Upgrade to 0.16.0 first, so the new Services already have ready pods when traffic moves to them. Then, before you upgrade to 0.17.0, move everything that still uses <fullname>:

  1. If tls.secretName is set, reissue the certificate to also cover <fullname>-api and <fullname>-duo-workflow, with their .<namespace>.svc forms, before you move any client. Once the chart's Gateway API routes move, each new Service has its own BackendTLSPolicy, which checks the certificate for that Service's .<namespace>.svc name, or for backendTLSPolicy.hostname on both when it is set.
  2. In the GitLab Duo admin settings, change <fullname> to <fullname>-api in the Local AI Gateway URL, and to <fullname>-duo-workflow in the Local URL for the GitLab Duo Agent Platform service.
  3. Set grpc-tls-proxy.upstream.host to <fullname>-duo-workflow.
  4. Point any other client of <fullname> at the new Service for its port.
  5. Remove any livenessProbe override that checks port 50052. Top-level probes apply only to the API pod, which no longer listens on 50052.

Setting legacyService.enabled: false on 0.16.0 makes the same change early: it removes <fullname>, moves the chart's Ingresses and routes to the new Services, and stops the Duo Workflow Service in the API pod.

JWT Signing Keys

The AI Gateway requires RSA signing and validation keys for issuing short-lived JWTs. There are two sets of keys:

  • AI Gateway keys (AIGW_SELF_SIGNED_JWT__SIGNING_KEY / AIGW_SELF_SIGNED_JWT__VALIDATION_KEY) - used by the AI Gateway for features like Duo Chat.
  • Duo Workflow keys (DUO_WORKFLOW_SELF_SIGNED_JWT__SIGNING_KEY / DUO_WORKFLOW_SELF_SIGNED_JWT__VALIDATION_KEY) - used by the GitLab Duo Agent Platform.

By default, the chart auto-generates all four RSA keys and stores them in a Kubernetes Secret named <release>-jwt-keys. No additional configuration is needed.

Using your own keys (optional)

If you need to manage keys externally (for example, for key rotation or to share keys across deployments), you can point the chart to a pre-existing Kubernetes Secret instead.

  1. Generate the keys:

    openssl genrsa -out aigw_signing.key 2048
    openssl genrsa -out aigw_validation.key 2048
    openssl genrsa -out duo_workflow_signing.key 2048
    openssl genrsa -out duo_workflow_validation.key 2048
    
  2. Create the Secret:

    kubectl -n ai-gateway create secret generic my-jwt-secret \
      --from-file=aigw-signing-key=aigw_signing.key \
      --from-file=aigw-validation-key=aigw_validation.key \
      --from-file=duo-workflow-signing-key=duo_workflow_signing.key \
      --from-file=duo-workflow-validation-key=duo_workflow_validation.key
    
  3. Reference the Secret in your values.yaml:

    aigwSigningKey:
      secret: "my-jwt-secret"
      key: "aigw-signing-key"
    aigwValidationKey:
      secret: "my-jwt-secret"
      key: "aigw-validation-key"
    
    duoWorkflowSigningKey:
      secret: "my-jwt-secret"
      key: "duo-workflow-signing-key"
    duoWorkflowValidationKey:
      secret: "my-jwt-secret"
      key: "duo-workflow-validation-key"
    

You can mix and match - for example, provide your own AI Gateway keys while letting the chart auto-generate the Duo Workflow keys, or vice versa.

Local development

To test any changes during local development, perform the following steps.

  1. Setup a Kubernetes cluster. Rancher Desktop, Minikube or any other Kubernetes distribution should work.

  2. Install Helm.

  3. Create a test.values.yaml file with the following context

    image:
      tag: latest
    
    logging:
      level: "debug"
      json: false
    
    gitlab:
      url: "http://gdk.test:3000/"
      apiUrl: "http://gdk.test:3000/api/v4/"
    
    customerPortalUrl: "http://gdk.test:5000/"
    
    anthropicApiKey:
      value: "REPLACE_ME"
    
    vertexTextModel:
      project: "REPLACE_ME"
      jsonKey:
        value: |-
          {
            "type": "service_account",
            "project_id": "REPLACE_ME",
            "private_key_id": "REPLACE_ME",
            "private_key": "REPLACE_ME",
            "client_email": "REPLACE_ME",
            "client_id": "REPLACE_ME",
            "auth_uri": "https://accounts.google.com/o/oauth2/auth",
            "token_uri": "https://oauth2.googleapis.com/token",
            "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
            "client_x509_cert_url": "REPLACE_ME",
            "universe_domain": "googleapis.com"
          }
    
    extraEnvironmentVariables:
      - name: TEST
        value: test
    
  4. Replace all instances of REPLACE_ME in the above file with appropriate values.

  5. Tip - Follow https://developers.google.com/workspace/guides/create-credentials if you need to create the GOOGLE_APPLICATION_CREDENTIALS.

  6. Verify the helm chart is rendering correctly

    helm template ai-gateway-test . \
      -f values.yaml \
      -f test.values.yaml
    
  7. Install the helm chart

    helm upgrade --install ai-gateway . \
      --namespace ai-gateway \
      --create-namespace \
      --set="gitlab.url=<your-local-gitlab>" \
      --set="gitlab.apiUrl=<your-local-gitlab>/api/v4/"
    
  8. Access the AI Gateway locally

    Get the pod name

    export POD_NAME=$(kubectl get pods --namespace ai-gateway-test -l "app.kubernetes.io/name=ai-gateway,app.kubernetes.io/instance=ai-gateway-test" -o jsonpath="{.items[0].metadata.name}")
    

    Get the AI Gateway server's port and portforward from local to the pod

    export CONTAINER_PORT=$(kubectl get pod --namespace ai-gateway-test $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
    kubectl --namespace ai-gateway-test port-forward $POD_NAME 5052:$CONTAINER_PORT
    

    You should be able to access the AI Gateway now

    $ curl localhost:5052/docs
    {"error":"No authorization header presented"}
    
  9. Access the Duo Workflow Service locally

    If you have a terminal running a port-forward, open a new terminal window.

    Follow the Duo Workflow Service logs

    kubectl --namespace ai-gateway-test logs -f deployment/ai-gateway-test-duo-workflow
    

    Get the Workflow service port and portforward from local to the pod

    export CONTAINER_PORT=$(kubectl get deployment --namespace ai-gateway-test ai-gateway-test-duo-workflow -o jsonpath="{.spec.template.spec.containers[0].ports[0].containerPort}")
    kubectl --namespace ai-gateway-test port-forward deployment/ai-gateway-test-duo-workflow 50052:$CONTAINER_PORT
    

    You should be able to access the Workflow service through gRPC now

    $ grpcurl  -plaintext localhost:50052 list
    DuoWorkflow
    grpc.reflection.v1alpha.ServerReflection
    Timing Data: 15.602496ms
      Dial: 5.341735ms
        BlockingDial: 5.309769ms
    
  10. Test locally with ingress

  11. Setup a fresh cluster with NGINX Ingress.

  12. Install the chart and enabled the grpc ingress.

```
$ helm upgrade --install aigw . -n aigw --create-namespace \
    -f test.values.yaml \
    --set ingress.enabled=true \
    --set ingress.className=nginx
```
  1. Confirm HTTP is forwarded to the AI gateway backend:
```bash
$ curl http://chart-example.local:80
{"error":"No authorization header presented"}
```
  1. Confirm GRPC is forwarded to the Duo Workflow backend:
```bash
$ grpcurl -vv -plaintext grpc-chart-example.local:80 list
DuoWorkflow
grpc.reflection.v1alpha.ServerReflection
Timing Data: 15.602496ms
  Dial: 5.341735ms
    BlockingDial: 5.309769ms
```
  1. Delete the helm chart

    helm -n ai-gateway-test delete ai-gateway-test
    

Build and publish assets

To release a new version of the GitLab Helm chart:

  1. Update the version and appVersion in Chart.yaml to the desired release version.
  2. Double-check the chart version in Chart.yaml before proceeding.
  3. Merge the changes to the main branch.
  4. Push a git tag matching the chart version (e.g., v0.7.0).
    git tag v0.7.0
    git push origin v0.7.0
    

Pushing the git tag will automatically trigger the CI/CD pipeline, which will build and publish the Helm chart to the GitLab package registry.

GitLab chart integration

When this chart is deployed as a subchart of the GitLab parent chart, it honours global.image.pullSecrets so image pull secrets can be configured centrally for all GitLab components.

global:
  image:
    pullSecrets:
      - name: my-registry-secret

Behavior:

  • global.image.pullSecrets must be a list of {name: <secret-name>} entries, matching the Kubernetes imagePullSecrets shape and the parent chart's convention.
  • global.image.pullSecrets and the chart-local imagePullSecrets are merged: global entries first, then local entries. This mirrors the parent chart's gitlab.image.pullSecrets helper, so a component-specific registry secret can be added without losing the shared one.
  • When only one of the two is set, only that list is rendered. When neither is set, no imagePullSecrets block is emitted.
  • The grpc-tls-proxy subchart applies the same logic for its own pod, merging global.image.pullSecrets with grpc-tls-proxy.imagePullSecrets.

You can verify the rendered secrets with:

helm template . \
  --set 'global.image.pullSecrets[0].name=my-registry-secret' \
  --set 'imagePullSecrets[0].name=my-component-secret'

Both secrets should appear under imagePullSecrets in the Deployment manifests.

gRPC TLS Proxy

The chart includes a grpc-tls-proxy subchart that runs a standalone NGINX pod to provide TLS termination for the Duo Workflow Service gRPC endpoint (port 50052). When enabled, the gRPC ingress routes external traffic through the proxy over TLS, making the Duo Agent Platform service accessible to GitLab without any manual post-upgrade patching.

Traffic flow:

GitLab → ingress:443 (GRPCS) → grpc-tls-proxy:8443 (TLS termination) → ai-gateway-duo-workflow:5

Deploy ai-gateway with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has ai-gateway on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartai-gateway is pinned at v19.6.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply