{"library":"prefect-kubernetes","title":"Prefect Kubernetes Integration","description":"Prefect-kubernetes provides integrations for running Prefect flows on Kubernetes. It enables Prefect 2.x deployments to provision Kubernetes Jobs for flow runs using `KubernetesDeployment` and manage them with `KubernetesWorker`. The current version is 0.7.7, and it follows the Prefect core library's release cadence, with integrations typically updated alongside major Prefect releases.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install prefect-kubernetes"],"cli":{"name":"prefect","version":"3.7.1"}},"imports":["from prefect_kubernetes.deployments import KubernetesDeployment","from prefect_kubernetes.workers import KubernetesWorker"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom prefect import flow\nfrom prefect_kubernetes.deployments import KubernetesDeployment\n\n# 1. Define a simple Prefect Flow\n@flow(log_prints=True)\ndef hello_kubernetes_flow(name: str = \"world\"):\n    import platform\n    print(f\"Hello, {name} from Kubernetes! Running on {platform.node()}\")\n\n# 2. Create a Kubernetes Deployment definition\n# This deployment will tell Prefect how to run `hello_kubernetes_flow` on Kubernetes.\n# It requires a work pool named \"kubernetes-work-pool\" to exist in your Prefect server.\n# Create it with: `prefect work-pool create kubernetes-work-pool --type kubernetes`\n\n# IMPORTANT: The 'image' specified here must contain your flow code and Prefect installed.\n# For a real scenario, you would build a custom Docker image for your flow.\n# Example custom image setup:\n#   Dockerfile:\n#     FROM prefecthq/prefect:2-python3.10\n#     COPY quickstart_kubernetes.py /app/quickstart_kubernetes.py\n#     WORKDIR /app\n#   Build & Push:\n#     docker build -t your-registry/your-flow-image:latest .\n#     docker push your-registry/your-flow-image:latest\n# Then use `your-registry/your-flow-image:latest` below.\n\ntry:\n    deployment = KubernetesDeployment(\n        name=\"hello-kubernetes-flow-deployment\",\n        description=\"Runs a simple 'Hello, Kubernetes!' flow on Kubernetes.\",\n        flow_name=hello_kubernetes_flow.name,\n        work_pool_name=\"kubernetes-work-pool\", # This work pool MUST exist in your Prefect server\n        image=\"prefecthq/prefect:2-python3.10\", # Base Prefect image; replace for custom flows\n        entrypoint=\"quickstart_kubernetes.py:hello_kubernetes_flow\", # Assumes this code is saved as quickstart_kubernetes.py\n        # You can also pass job_variables or infra_overrides for custom Kubernetes Job spec\n        # job_variables={\"MY_ENV_VAR\": \"my_value\"},\n        # infra_overrides={\n        #     \"job_template\": {\n        #         \"spec\": {\"template\": {\"spec\": {\"nodeSelector\": {\"kubernetes.io/hostname\": \"your-node\"}}}}\n        #     }\n        # }\n    )\n    deployment_id = deployment.apply()\n    print(f\"Deployment '{deployment.name}' created/updated with ID: {deployment_id}\")\n\nexcept Exception as e:\n    print(f\"Failed to create Kubernetes Deployment: {e}\")\n    print(\"Ensure PREFECT_API_URL is set and Prefect server is running.\")\n\n# To start the Kubernetes Worker that will pick up runs for this deployment:\n# prefect worker start --pool kubernetes-work-pool\n","lang":"python","description":"This quickstart demonstrates how to define a Prefect flow and then create a `KubernetesDeployment` object to run it on a Kubernetes cluster. To make this runnable:\n1. Ensure a Prefect server (e.g., `prefect server start`) and a Kubernetes cluster are running.\n2. Configure your `kubectl` context to point to your cluster.\n3. Set your `PREFECT_API_URL` environment variable to point to your Prefect server.\n4. Create a Kubernetes work pool: `prefect work-pool create kubernetes-work-pool --type kubernetes`.\n5. Save the provided Python code as `quickstart_kubernetes.py` and run it: `python quickstart_kubernetes.py`. This will register the deployment with your Prefect server.\n6. Start a Kubernetes worker: `prefect worker start --pool kubernetes-work-pool`.\n7. Create a flow run from the Prefect UI or CLI: `prefect deployment run 'hello-kubernetes-flow-deployment'`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"0.6.6","pypi_latest":"0.7.9","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":25,"avg_import_s":null,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"299.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":27.6,"import_time_s":null,"mem_mb":null,"disk_size":"301M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"326.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":26.1,"import_time_s":null,"mem_mb":null,"disk_size":"329M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"314.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":21.2,"import_time_s":null,"mem_mb":null,"disk_size":"318M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"311.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":21,"import_time_s":null,"mem_mb":null,"disk_size":"314M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"227.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"prefect-kubernetes","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":29.3,"import_time_s":null,"mem_mb":null,"disk_size":"230M"}]}}