Pulumi Kubernetes Provider
pulumi-kubernetes is a Pulumi package for creating and managing Kubernetes resources using Python, allowing Infrastructure as Code deployments. It is currently at version 4.28.0 and follows a regular release cadence, often aligning with new Kubernetes API versions and Pulumi core updates.
Warnings
- breaking The `pulumi.com/waitFor` annotation's JSONPath parser was updated to an RFC9535-compliant standard in v4.24.0. Users relying on specific, non-compliant JSONPath expressions for resource waiting might experience changes in behavior or failures.
- gotcha Enabling both `alwaysRender` and `renderYAMLtoDirectory` in the provider configuration (v4.26.0) can lead to every `pulumi up` showing diffs for YAML manifests, even if the underlying resources haven't logically changed. This opt-in behavior can increase noise during updates.
- gotcha The provider frequently updates its underlying Kubernetes schemas and client libraries (e.g., to v1.33.0 in v4.23.0). This can introduce changes in resource specifications, deprecations of older API versions, or new required fields. Ensure your resource definitions are compatible with the target Kubernetes API server version.
- gotcha The provider has addressed multiple race conditions related to resource awaiting and deletion (e.g., StatefulSet rollout, Deleted condition in v4.26.0, v4.22.1, v4.22.0). This indicates that resource readiness and cleanup might behave unexpectedly or be unreliable in older versions, potentially leading to 'stuck' updates or resources.
- gotcha Helm resource fields, such as `valueYamlFiles` (fixed in v4.22.2 for panic on nil) or `plainHttp` (added in v4.24.0 to `v4.Chart`), can have specific behaviors or edge cases. Misconfiguration or reliance on older versions might lead to unexpected errors or deployment failures.
Install
-
pip install pulumi-kubernetes
Imports
- Provider
from pulumi_kubernetes import Provider
- Deployment
from pulumi_kubernetes.apps.v1 import Deployment
- Namespace
from pulumi_kubernetes.core.v1 import Namespace
- Service
from pulumi_kubernetes.core.v1 import Service
- Chart
from pulumi_kubernetes.helm.v3 import Chart
- Resource
from pulumi_kubernetes.yaml import ConfigFile, ConfigGroup
Quickstart
import pulumi
import pulumi_kubernetes as kubernetes
# Create a Kubernetes Namespace
my_namespace = kubernetes.core.v1.Namespace(
"my-namespace",
metadata={
"name": "test-ns-from-pulumi",
"labels": {"environment": "dev"}
}
)
# Export the name of the namespace
pulumi.export("namespace_name", my_namespace.metadata["name"])
# To run:
# 1. Ensure KUBECONFIG is set or your ~/.kube/config is configured.
# 2. pulumi new python --dir my-k8s-project
# 3. cd my-k8s-project
# 4. pip install pulumi-kubernetes
# 5. Replace __main__.py content with this code.
# 6. pulumi up