<@ULVA73B9P> how do I change the namespace a worke...
# ask-marvin
p
@Marvin how do I change the namespace a worker pool is modifying in the helm chart?
m
thought for 270.4 seconds
Great question. In Prefect 3.x, the Kubernetes namespace that a worker pool “modifies” (i.e., where it creates Jobs for your flow runs) is controlled by the work pool’s base job template, not by the worker’s own install namespace. When deploying the worker via the Helm chart, you change this by customizing the base job template in values.yaml. Quick overview: - Jobs are created in the namespace defined by the base job template variable
namespace
(defaults to
default
). - You can set that default in the Helm chart under
worker.config.baseJobTemplate.configuration
. - There’s also a
worker.config.jobNamespace
value, but that only controls which namespaces the worker’s observer watches for pod events; it does not control where jobs are created. How to set the job creation namespace via Helm (values.yaml):
Copy code
worker:
  config:
    workPool: my-k8s-pool
    baseJobTemplate:
      configuration: |
        {
          "variables": {
            "namespace": {
              "default": "my-target-namespace",
              "type": "string",
              "description": "The Kubernetes namespace to create jobs within."
            }
          },
          "job_configuration": {
            "job_manifest": {
              "metadata": {
                "namespace": "{{ namespace }}"
              }
            }
          }
        }
Notes: - Default behavior: if you do nothing, jobs are created in the Kubernetes “default” namespace. - Per-deployment override: you can override the namespace per deployment using `job_variables`:
Copy code
deployments:
    - name: my-deployment
      work_pool:
        name: my-kubernetes-pool
        job_variables:
          namespace: staging
- Observer vs. job creation: if you meant “which namespaces the worker watches for pod events,” set:
Copy code
worker:
    config:
      jobNamespace: "default,my-target-namespace"
This does not affect where jobs are created. Helpful links: - Prefect Kubernetes guide (work pools and namespace behavior): Kubernetes deployment guide - Customizing base job templates: Customize base job templates - Helm chart (prefect-worker) README and values: - prefect-worker chart README - values.yaml - Self-hosting/Helm overview: Self-host with Helm Do you want to: - change the namespace where the worker itself is installed (Helm release namespace), or - change the namespace where it creates Jobs, or - change which namespaces it observes for pod events? If it’s the second, the base job template shown above is the right approach. Also ensure the worker’s ServiceAccount has RBAC permissions in the target namespace(s).
p
@Marvin Isn't there a way to modify the default namespace of the worker pool without changing the whole job template? I feel like those are two different things
m
thought for 254.6 seconds
Short answer: there isn’t a separate “default namespace” knob for a work pool that’s independent of its base job template. In Prefect 3.x, the pool’s defaults (including
namespace
) live in the base job template’s
variables
section. So changing the default namespace means updating that template. That said, you don’t have to rewrite the whole manifest—just change the
variables.namespace.default
and leave everything else as-is. Easiest options: - Prefect UI: Work Pools → your Kubernetes pool → Edit → set the “Namespace” field → Save. Under the hood this updates the base job template’s default for
namespace
. - Prefect CLI (verified):
Copy code
prefect work-pool get-default-base-job-template --type kubernetes -f base-job-template.json
  # edit base-job-template.json -> set variables.properties.namespace.default to your value
  prefect work-pool update <your-pool> --base-job-template base-job-template.json
- Helm (bake it in): Provide the full template JSON (with only the default changed) via
worker.config.baseJobTemplate.configuration
. Per-deployment alternative (no pool default change):
Copy code
deployments:
  - name: my-deployment
    work_pool:
      name: my-kubernetes-pool
      job_variables:
        namespace: staging
Notes: -
worker.config.jobNamespace
in the Helm chart only controls which namespaces the worker’s observer watches; it does not set where jobs are created. - Default behavior if you do nothing: jobs are created in the
default
Kubernetes namespace. Docs: - Kubernetes guide: Kubernetes deployment guide - Customize base job templates: Customize base job templates - Helm chart: prefect-worker chart README and values.yaml If you’d like, tell me your target namespace and I can generate a minimal base job template snippet that only changes that default while leaving everything else intact.