prefect-worker

by prefect

Helm chartv2026.11.24211251App 3.9.5Verified publisher

Prefect Worker application bundle

About this chart

prefect-worker

Overview

Workers are lightweight polling services that retrieve scheduled runs from a work pool and execute them.

Workers each have a type corresponding to the execution environment to which they will submit flow runs. Workers are only able to join work pools that match their type. As a result, when deployments are assigned to a work pool, you know in which execution environment scheduled flow runs for that deployment will run.

Installing the Chart

Prerequisites

  1. Add the Prefect Helm repository to your Helm client:
    helm repo add prefect https://prefecthq.github.io/prefect-helm
    helm repo update
  1. Create a new namespace in your Kubernetes cluster to deploy the Prefect worker in:
    kubectl create namespace prefect

Configuring a Worker for Prefect Cloud

  1. Create a Kubernetes secret for a Prefect Cloud API key

    First create a file named api-key.yaml with the following contents:

    apiVersion: v1
    kind: Secret
    metadata:
      name: prefect-api-key
      namespace: prefect
    type: Opaque
    data:
      key:  <base64-encoded-api-key>
Replace `<base64-encoded-api-key>` with your Prefect Cloud API key encoded in base64. The helm chart looks for a secret of this name and schema, this can be overridden in the `values.yaml`.

You can use the following command to generate the base64-encoded value:
    echo -n "your-prefect-cloud-api-key" | base64
Then apply the `api-key.yaml` file to create the Kubernetes secret:
    kubectl apply -f api-key.yaml
Alternatively, you can create the Kubernetes secret via the cli with the following command. In this case, Kubernetes will take care of base64 encoding the value on your behalf:
    kubectl create secret generic prefect-api-key --from-literal=key=pnu_xxxx
  1. Configure the Prefect worker values

    Create a values.yaml file to customize the Prefect worker configuration. Add the following contents to the file:

    worker:
      cloudApiConfig:
        accountId: <target account ID>
        workspaceId: <target workspace ID>
      config:
        workPool: <target work pool name>
These settings will ensure that the worker connects to the proper account, workspace, and work pool.
View your Account ID and Workspace ID in your browser URL when logged into Prefect Cloud. For example: `https://app.prefect.cloud/account/abc-my-account-id-is-here/workspaces/123-my-workspace-id-is-here`

Configuring a Worker for Self-managed Cloud (not to be confused with Self-hosted Prefect Server)

  1. Create a Kubernetes secret for a Prefect Self-managed Cloud API key

    First create a file named api-key.yaml with the following contents:

    apiVersion: v1
    kind: Secret
    metadata:
      name: prefect-api-key
      namespace: prefect
    type: Opaque
    data:
      key:  <base64-encoded-api-key>
Replace `<base64-encoded-api-key>` with your Prefect Self-managed Cloud API key encoded in base64. The helm chart looks for a secret of this name and schema, this can be overridden in the `values.yaml`.

You can use the following command to generate the base64-encoded value:
    echo -n "your-prefect-self-managed-cloud-api-key" | base64
Then apply the `api-key.yaml` file to create the Kubernetes secret:
    kubectl apply -f api-key.yaml
Alternatively, you can create the Kubernetes secret via the cli with the following command. In this case, Kubernetes will take care of base64 encoding the value on your behalf:
    kubectl create secret generic prefect-api-key --from-literal=key=pnu_xxxx
  1. Configure the Prefect worker values

    Create a values.yaml file to customize the Prefect worker configuration. Add the following contents to the file:

    worker:
      apiConfig: customerManagedCloud
      config:
        workPool: <target work pool name>
      customerManagedCloudApiConfig:
        apiUrl: "https://<DNS of Self-managed Cloud API>"
        accountId: <target account ID>
        workspaceId: <target workspace ID>
These settings will ensure that the worker connects to the proper account, workspace, and work pool.
View your Account ID and Workspace ID in your browser URL when logged into Prefect Cloud. For example: `https://self-managed-prefect.company/account/abc-my-account-id-is-here/workspaces/123-my-workspace-id-is-here`

Configuring a Worker for Self-hosted Prefect Server

  1. Configure the Prefect worker values

    Create a values.yaml file to customize the Prefect worker configuration. Add the following contents to the file:

    worker:
      apiConfig: selfHostedServer
      config:
        workPool: <target work pool name>
      selfHostedServerApiConfig:
        apiUrl: <dns or ip address of the prefect-server pod here>
These settings will ensure the worker connects with the local deployment of Self-hosted Prefect Server.
If the Self-hosted Prefect Server pod is deployed in the same cluster, you can use the local Kubernetes DNS address to connect to it: `http://<prefect-server-service-name>.<namespace>.svc.cluster.local:<prefect-server-port>/api`. If the Self-hosted Prefect Server pod is deployed in a different cluster, set the apiUrl to the fully qualified domain name of the Self-hosted Prefect Server.

Installing & Verifying Deployment of the Prefect Worker

  1. Install the Prefect worker using Helm
    helm install prefect-worker prefect/prefect-worker --namespace=prefect -f values.yaml
  1. Verify the deployment

    Check the status of your Prefect worker deployment:

    kubectl get pods -n prefect

    NAME                              READY   STATUS    RESTARTS       AGE
    prefect-worker-658f89bc49-jglvt   1/1     Running   0              25m
You should see the Prefect worker pod running

Additional Worker Configurations

Container seccomp profile

The chart passes worker.containerSecurityContext to the worker container. Set seccompProfile there when a policy requires a profile on the container. For a Localhost profile, set localhostProfile to a path relative to the kubelet's seccomp profile directory.

worker:
  containerSecurityContext:
    seccompProfile:
      type: Localhost
      localhostProfile: profiles/restricted.json

Basic Auth

Prefect documentation on basic auth

Self-hosted Prefect servers can be equipped with a Basic Authentication string for an administrator/password combination. Assuming you are running a Self-hosted Prefect server with basic auth enabled, you can authenticate your worker with the same credentials.

The format of the auth string is admin:<my-password> (no brackets).

worker:
  basicAuth:
    enabled: true
    authString: "admin:pass"

Alternatively, you can provide an existing Kubernetes Secret containing the auth string credentials. The secret must contain a key auth-string with the value of the auth string.

kubectl create secret generic prefect-basic-auth --from-literal=auth-string='admin:my-password'
worker:
  basicAuth:
    enabled: true
    existingSecret: prefect-basic-auth

Deploying multiple workers to a single namespace

If you want to run more than one worker in a single Kubernetes namespace, you will need to specify the fullnameOverride parameter at install time of one of the workers.

fullnameOverride: prefect-worker-2

If you want the workers to share a service account, add the following to your values.yaml:

fullnameOverride: prefect-worker-2
serviceAccount:
  create: false
  name: "prefect-worker"

Configuring a Base Job Template on the Worker

The worker uses the base job template to create the Kubernetes job that executes your workflow. The base job template configuration can be modified by setting worker.config.baseJobTemplate.configuration.

  1. Define the base job template in a local file. To get a formatted template, run the following command & store locally in base-job-template.json:
# you may need to install `prefect-kubernetes` first
pip install prefect-kubernetes

prefect work-pool get-default-base-job-template --type kubernetes > base-job-template.json
  1. Modify the base job template as needed. Keep in mind that modifications are not merged with the default template. The configuration you provide will replace the default configuration entirely. See modifying the base job template for more information.

  2. Install the chart as you usually would, making sure to use the --set-file command to pass in the base-job-template.json file as a paramater:

helm install prefect-worker prefect/prefect-worker -f values.yaml --set-file worker.config.baseJobTemplate.configuration=base-job-template.json

Modifying the Base Job Template

Modifying the base job template replaces the default configuration entirely. Put differently, any provided configuration is not merged with the default configuration.

For example, if you want to add an image pull secret to the base job template, you would modify the base-job-template.json file to look like this:

{
 "job_configuration": {
   "job_manifest": {
     "spec": {
       "template": {
         "spec": {
           "imagePullSecrets": [
             {
               "name": "my-pull-secret"
             }
           ]
         }
       }
     }
   }
 }
}

Here, you add imagePullSecrets into your existing configuration. Note that the snippet is truncated for brevity. The full configuration should still be provided.

For comprehensive examples including environment variables, secret references, resource configurations, and advanced use cases, see the Prefect base job template documentation.

Once applied, you can see the entire base job template in the UI by navigating to Account settings > Work Pools > your work pool > three-dot menu in the top right corner > Edit > Base Job Template section > Advanced tab.

Updating the Base Job Template

If a base job template is set through Helm (via either worker.config.baseJobTemplate.configuration or worker.config.baseJobTemplate.existingConfigMapName), we'll run an optional initContainer that will sync the template configuration to the work pool named in worker.config.workPool.

Any time the base job template is updated, the subsequent initContainer run will run prefect work-pool update <work-pool-name> --base-job-template <template-json> and sync this template to the API.

Please note that configuring the template via baseJobTemplate.existingConfigMapName will require a manual restart of the prefect-worker Deployment in order to kick off the initContainer - alternatively, you can use a tool like reloader to automatically restart an associated Deployment. However, configuring the template via baseJobTemplate.configuration value will automatically roll the Deployment on any update.

Troubleshooting

Setting worker.clusterUid

This chart attempts to generate a unique identifier for the cluster it is installing the worker on to use as metadata for your runs. Since Kubernetes does not provide a "cluster ID" API, this chart will do so by reading the kube-system namespace and parsing the immutable UID. This mimics the functionality in the prefect-kubernetes library.

[!NOTE] Reading the kube-system namespace requires a ClusterRole with get permissions on namespaces, as well as a ClusterRoleBinding to attach it to the actor running the helm install.

A Role / RoleBinding may also be used, but it must exist in the kube-system namespace.

This chart does not offer a built-in way to assign these roles, as it does not make assumptions about your cluster's access controls to the kube-system namespace. If these permissions are not granted, you may see this error:

HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"namespaces "kube-system" is forbidden: User "system:serviceaccount:prefect:prefect-worker" cannot get resource "namespaces" in API group "" in the namespace "kube-system"","reason":"Forbidden","details":{"name":"kube-system","kind":"namespaces"},"code":403}

In many cases, these role additions may be entirely infeasible due to overall access limitations. As an alternative, this chart offers a hard-coded override via the worker.clusterUid value.

Set this value to a user-provided unique ID - this bypasses the kube-system namespace lookup and utilizes your provided value as the cluster ID instead. Be sure to set this value consistently across your Prefect deployments that interact with the same cluster

worker:
  # -- unique cluster identifier, if none is provided this value will be inferred at time of helm install
  clusterUid: "my-unique-cluster-id"

Maintainers

NameEmailUrl
jamiezieziula[email protected]
jimid27[email protected]
parkedwards<edw

Deploy prefect-worker with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has prefect-worker 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 chartprefect-worker is pinned at v2026.11.24211251 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