Krystal
03/08/2024, 4:16 PMsecretKeyRef for deploying prefect deployment on kubernetes I get is not of type \'object\'">'} . what is the correct format?Marvin
03/08/2024, 4:16 PMsecretKeyRef, it seems you are having an issue with the format, which has resulted in a type error. Although the specific format you require is not explicitly provided, the error message suggests that secretKeyRef must be an object.
A generic way to define secretKeyRef in Kubernetes manifests is as follows:
yaml
env:
  - name: SOME_SECRET_KEY
    valueFrom:
      secretKeyRef:
        name: name-of-the-secret
        key: key-in-the-secret
You would need to create a Kubernetes secret first and then reference it in your deployment manifests. Here's an example command to create a secret for a Prefect API key in Kubernetes:
bash
kubectl create secret generic prefect-api-key \
  --namespace=prefect --from-literal=key=your-prefect-cloud-api-key
This prefect-api-key secret can then be referenced in the deployment configuration using secretKeyRef.
Ensure you name the secret accordingly and that the key within secretKeyRef matches the key set when you created the Kubernetes secret.
For more information on managing Prefect Cloud API keys and details on deploying Prefect to Kubernetes (though not specific to secretKeyRef), you can refer to the following documents:
- Manage Prefect Cloud API Keys
- Deployment to Kubernetes Guide
If you're still having issues, it would be helpful to see the exact manifest or code snippet where you are using secretKeyRef to provide more tailored advice.Nate
03/08/2024, 4:17 PMKrystal
03/08/2024, 4:17 PMKrystal
03/08/2024, 4:18 PMname: "collect-api-results"
  cron: null
  description: "Collect api results workflow"
  job_variables:
    env:
      - name: LD_SDK_KEY
        valueFrom:
          secretKeyRef:
            name: prefect-ld-sdk-key
            key: ld-sdk-keyKrystal
03/08/2024, 4:18 PM.deploy()Krystal
03/08/2024, 4:19 PM.deploy(
        work_pool_name=constants.PrefectWorkpool.CPU.value,
        image=constants.PREFECT_WORKFLOW_IMAGE,
        build=False,
        push=False,
        **(what I have in the above),
    )Krystal
03/08/2024, 4:19 PMprefect.deployments.runner.DeploymentApplyError: Error creating deployment: <ValidationError: "[{'name': 'LD_SDK_KEY', 'valueFrom': {'secretKeyRef': {'name': 'prefect-ld-sdk-key', 'key': 'ld-sdk-key'}}}] is not of type 'object'">Krystal
03/08/2024, 4:20 PM"job_configuration": {
                "env": "{{ env }}",
                "name": "{{ name }}",
                "labels": "{{ labels }}",
                "command": "{{ command }}",
                "namespace": "{{ namespace }}",
                "job_manifest": {
                    "kind": "Job",
                    "spec": {
                        "template": {
                            "spec": {
                                "tolerations": "{{ tolerations }}",
                                "containers": [
                                    {
                                        "env": "{{ env }}",
                                        "args": "{{ command }}",
                                        "name": "prefect-job",
                                        "image": "{{ image }}",
                                        "imagePullPolicy": "{{ image_pull_policy }}",
                                        "resources": "{{ resources }}"
                                    }
                                ],
                                "completions": 1,
                                "parallelism": 1,
                                "restartPolicy": "Never",
                                "serviceAccountName": "prefect-worker"
                            }
                        },
                        "backoffLimit": 0,
                        "ttlSecondsAfterFinished": "{{ finished_job_ttl }}"
                    },
                    "metadata": {
                        "labels": "{{ labels }}",
                        "namespace": "{{ namespace }}",
                        "generateName": "{{ name }}-"
                    },
                    "apiVersion": "batch/v1"
                },
                "stream_output": "{{ stream_output }}",
                "cluster_config": "{{ cluster_config }}",
                "job_watch_timeout_seconds": "{{ job_watch_timeout_seconds }}",
                "pod_watch_timeout_seconds": "{{ pod_watch_timeout_seconds }}"
                }
            }Krystal
03/08/2024, 4:20 PMKrystal
03/08/2024, 4:27 PM{{ env }} inside and outside of "job_manifest" in the config?Nate
03/08/2024, 4:27 PMname: "collect-api-results"
  cron: null
  description: "Collect api results workflow"
  job_variables:
    env:
      - name: LD_SDK_KEY
        valueFrom:
          secretKeyRef:
            name: prefect-ld-sdk-key
            key: ld-sdk-key
i think what you want is something like this
{
  "job_configuration": {
    "env": "{{ env }}",
    "name": "{{ name }}",
    "labels": "{{ labels }}",
    "command": "{{ command }}",
    "namespace": "{{ namespace }}",
    "job_manifest": {
      "kind": "Job",
      "spec": {
        "template": {
          "spec": {
            "tolerations": "{{ tolerations }}",
            "containers": [
              {
                "env": [
                  {
                    "name": "LD_SDK_KEY",
                    "valueFrom": {
                      "secretKeyRef": {
                        "name": "prefect-ld-sdk-key",
                        "key": "ld-sdk-key"
                      }
                    }
                  },
                ],
                "args": "{{ command }}",
                "name": "prefect-job",
                "image": "{{ image }}",
                "imagePullPolicy": "{{ image_pull_policy }}",
                "resources": "{{ resources }}"
              }
            ],
            "completions": 1,
            "parallelism": 1,
            "restartPolicy": "Never",
            "serviceAccountName": "prefect-worker"
          }
        },
        "backoffLimit": 0,
        "ttlSecondsAfterFinished": "{{ finished_job_ttl }}"
      },
      "metadata": {
        "labels": "{{ labels }}",
        "namespace": "{{ namespace }}",
        "generateName": "{{ name }}-"
      },
      "apiVersion": "batch/v1"
    },
    "stream_output": "{{ stream_output }}",
    "cluster_config": "{{ cluster_config }}",
    "job_watch_timeout_seconds": "{{ job_watch_timeout_seconds }}",
    "pod_watch_timeout_seconds": "{{ pod_watch_timeout_seconds }}"
  }
}Krystal
03/08/2024, 4:29 PM{
  "job_configuration": {
    "env": "{{ env }}",
    "name": "{{ name }}",
    "labels": "{{ labels }}",
    "command": "{{ command }}",
    "namespace": "{{ namespace }}",
    "job_manifest": {
      "kind": "Job",
      "spec": {
        "template": {
          "spec": {
            "tolerations": "{{ tolerations }}",
            "containers":
              {
                "container_env": "{{ container_env }}",
                "args": "{{ command }}",
                "name": "prefect-job",
                "image": "{{ image }}",
                "imagePullPolicy": "{{ image_pull_policy }}",
                "resources": "{{ resources }}"
              }
            ],
            "completions": 1,
            "parallelism": 1,
            "restartPolicy": "Never",
            "serviceAccountName": "prefect-worker"
          }
        },
        "backoffLimit": 0,
        "ttlSecondsAfterFinished": "{{ finished_job_ttl }}"
      },
      "metadata": {
        "labels": "{{ labels }}",
        "namespace": "{{ namespace }}",
        "generateName": "{{ name }}-"
      },
      "apiVersion": "batch/v1"
    },
    "stream_output": "{{ stream_output }}",
    "cluster_config": "{{ cluster_config }}",
    "job_watch_timeout_seconds": "{{ job_watch_timeout_seconds }}",
    "pod_watch_timeout_seconds": "{{ pod_watch_timeout_seconds }}"
  }
}
And then pass in the config like below?
name: "collect-api-results"
  cron: null
  description: "Collect api results workflow"
  job_variables:
    container_env:
      - name: LD_SDK_KEY
        valueFrom:
          secretKeyRef:
            name: prefect-ld-sdk-key
            key: ld-sdk-keyNate
03/08/2024, 4:30 PMprefect.yaml you'd have to pass the whole job_manifest as a yaml object (which you could create a yaml definition for)Krystal
03/08/2024, 4:30 PMKrystal
03/08/2024, 4:31 PMNate
03/08/2024, 4:31 PMcontainer_env wouldnt be at the "right level" to be one of the valid job_variablesNate
03/08/2024, 4:31 PMjob_manifest isKrystal
03/08/2024, 4:32 PMKrystal
03/08/2024, 4:33 PMKrystal
03/08/2024, 4:34 PMbaseJobTemplateName: prefect-worker-cpu-base-job-template # -- JSON formatted base job template. If unspecified, Prefect will use the default base job template for the given worker type. If the work pool already exists, this will be ignored.
From the helm values.yaml. Unless you know of a way where i can overwrite that with changes?Nate
03/08/2024, 4:38 PMif you wanted to do all the stuff into clarify, your job config should be mostly unrelated to your worker, i.e. you should not need to delete / alter your work pool or worker to change your job config you can alter youryou'd have to pass the wholeprefect.yamlas a yaml object (which you could create a yamljob_manifestfor)definition
job_manifest on a deployment basis by specifying it in your deployment definition in prefect.yaml like this
name: "collect-api-results"
  cron: null
  description: "Collect api results workflow"
  job_variables:
    job_manifest:
      kind: Job
      ...
and to reiterate, to avoid a bunch of boilerplate, you can create yaml definitions that you can re-use for these job manifests, or create more granular definitions for your container specs so you can slot them into different manifests as neededKrystal
03/08/2024, 4:42 PMNate
03/08/2024, 4:43 PM