<@ULVA73B9P> can I use `KubernetesJob.from_yaml_fi...
# ask-marvin
p
@Marvin can I use
KubernetesJob.from_yaml_file
to override parameters in k8s job yaml file?
m
Yes, you can use
KubernetesJob.from_yaml_file
to override parameters in a Kubernetes job YAML file. You can define a
KubernetesJob
infrastructure block in Python and use the
customizations
parameter to add or modify specific paths in the Kubernetes job specification. Here's an example:
Copy code
customizations = [
  {
    "op": "add",
    "path": "/spec/template/spec/containers/0/resources",
    "value": {
      "requests": {
        "cpu": "2000m",
        "memory": "4gi"
      },
      "limits": {
        "cpu": "4000m",
        "memory": "8Gi",
        "<http://nvidia.com/gpu|nvidia.com/gpu>": "1"
      }
    },
  }
]

k8s_job = KubernetesJob(
  namespace=namespace,
  image=image_name,
  image_pull_policy=KubernetesImagePullPolicy.ALWAYS,
  finished_job_ttl=300,
  job_watch_timeout_seconds=600,
  pod_watch_timeout_seconds=600,
  service_account_name="prefect-server",
  customizations=customizations,
)

k8s_job.save("devk8s")
In this example, the
customizations
parameter is used to add resource requests and limits to the first container in the Kubernetes job specification. Please note that you need to have
kubectl
available and configure remote storage as local storage is not supported for Kubernetes. Also, the ephemeral Prefect API won't work with Docker and Kubernetes. You must have a Prefect server or Prefect Cloud API endpoint set in your agent's configuration. For more details, you can refer to the Prefect documentation.
p
@Marvin what about
KubernetesJob(JobBlock)
?
m
The
KubernetesJob(JobBlock)
is an infrastructure block in Prefect that executes flow runs in a Kubernetes Job. Here are some of its requirements and supported settings: Requirements: -
kubectl
must be available. - You must configure remote Storage. Local storage is not supported for Kubernetes. - The ephemeral Prefect API won't work with Docker and Kubernetes. You must have a Prefect server or Prefect Cloud API endpoint set in your agent's configuration. Supported Settings: - `cluster_config`: An optional Kubernetes cluster config to use for this job. - `command`: A list of strings specifying the command to run in the container to start the flow run. In most cases, you should not override this. - `customizations`: A list of JSON 6902 patches to apply to the base Job manifest. Alternatively, a valid JSON string is allowed (handy for deployments CLI). - `env`: Environment variables to set for the container. - `finished_job_ttl`: The number of seconds to retain jobs after completion. If set, finished jobs will be cleaned up by Kubernetes after the given delay. If None (default), jobs will need to be manually removed. - `image`: String specifying the tag of a Docker. For more details, you can refer to the Prefect documentation.