Get started with Pulumi in a free one hour introductory workshop. Register Now

This page documents the language specification for the kubernetes package. If you're looking for help working with the inputs, outputs, or functions of kubernetes resources in a Pulumi program, please see the resource documentation for examples and API reference.

Pulumi Kubernetes

class pulumi_kubernetes.ConfigFile(name: str, file: Optional[str] = None, opts: Optional[pulumi.resource.ResourceOptions] = None, transformations: Optional[Sequence[Callable[[Any, pulumi.resource.ResourceOptions], None]]] = None, resource_prefix: Optional[str] = None, file_id: Optional[str] = None)

ConfigFile creates a set of Kubernetes resources from a Kubernetes YAML file.

from pulumi_kubernetes.yaml import ConfigFile

example = ConfigFile(
    "example",
    file="foo.yaml",
)
from pulumi_kubernetes.yaml import ConfigFile

# Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
def make_service_private(obj, opts):
    if obj["kind"] == "Service" and obj["apiVersion"] == "v1":
        try:
            t = obj["spec"]["type"]
            if t == "LoadBalancer":
                obj["spec"]["type"] = "ClusterIP"
        except KeyError:
            pass


# Set a resource alias for a previous name.
def alias(obj, opts):
    if obj["kind"] == "Deployment":
        opts.aliases = ["oldName"]


# Omit a resource from the Chart by transforming the specified resource definition to an empty List.
def omit_resource(obj, opts):
    if obj["kind"] == "Pod" and obj["metadata"]["name"] == "test":
        obj["apiVersion"] = "v1"
        obj["kind"] = "List"


example = ConfigFile(
    "example",
    file="foo.yaml",
    transformations=[make_service_private, alias, omit_resource],
)
Parameters
  • name (str) – A name for a resource.

  • file (Optional[str]) – Path or a URL that uniquely identifies a file.

  • opts (Optional[pulumi.ResourceOptions]) – A bag of optional settings that control a resource’s behavior.

  • pulumi.ResourceOptions], None]]] transformations (Optional[Sequence[Callable[[Any,) – A set of transformations to apply to Kubernetes resource definitions before registering with engine.

  • resource_prefix (Optional[str]) – An optional prefix for the auto-generated resource names. Example: A resource created with resource_prefix=”foo” would produce a resource named “foo-resourceName”.

resources: pulumi.Output[dict] = None

Kubernetes resources contained in this ConfigFile.

translate_output_property(prop: str) → str

Provides subclasses of Resource an opportunity to translate names of output properties into a format of their choosing before writing those properties to the resource object.

Parameters

prop (str) – A property name.

Returns

A potentially transformed property name.

Return type

str

translate_input_property(prop: str) → str

Provides subclasses of Resource an opportunity to translate names of input properties into a format of their choosing before sending those properties to the Pulumi engine.

Parameters

prop (str) – A property name.

Returns

A potentially transformed property name.

Return type

str

get_resource(group_version_kind: str, name: str, namespace: Optional[str] = None) → pulumi.output.Output[pulumi.resource.CustomResource][pulumi.resource.CustomResource]

get_resource returns a resource defined by a built-in Kubernetes group/version/kind and name. For example: get_resource("apps/v1/Deployment", "nginx")

Parameters
  • group_version_kind (str) – Group/Version/Kind of the resource, e.g., apps/v1/Deployment

  • name (str) – Name of the resource to retrieve

  • namespace (Optional[str]) – Optional namespace of the resource to retrieve

class pulumi_kubernetes.ConfigGroup(name: str, files: Optional[Sequence[str]] = None, yaml: Optional[Sequence[str]] = None, opts: Optional[pulumi.resource.ResourceOptions] = None, transformations: Optional[Sequence[Callable[[Any, pulumi.resource.ResourceOptions], None]]] = None, resource_prefix: Optional[str] = None)

ConfigGroup creates a set of Kubernetes resources from Kubernetes YAML text. The YAML text may be supplied using any of the following methods:

  1. Using a filename or a list of filenames:

  2. Using a file pattern or a list of file patterns:

  3. Using a literal string containing YAML, or a list of such strings:

  4. Any combination of files, patterns, or YAML strings:

from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    files=["foo.yaml"],
)
from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    files=["foo.yaml", "bar.yaml"],
)
from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    files=["yaml/*.yaml"],
)
from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    files=["foo/*.yaml", "bar/*.yaml"],
)
from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    yaml=['''
apiVersion: v1
kind: Namespace
metadata:
  name: foo
''']
)
from pulumi_kubernetes.yaml import ConfigGroup

# Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
def make_service_private(obj, opts):
    if obj["kind"] == "Service" and obj["apiVersion"] == "v1":
        try:
            t = obj["spec"]["type"]
            if t == "LoadBalancer":
                obj["spec"]["type"] = "ClusterIP"
        except KeyError:
            pass


# Set a resource alias for a previous name.
def alias(obj, opts):
    if obj["kind"] == "Deployment":
        opts.aliases = ["oldName"]


# Omit a resource from the Chart by transforming the specified resource definition to an empty List.
def omit_resource(obj, opts):
    if obj["kind"] == "Pod" and obj["metadata"]["name"] == "test":
        obj["apiVersion"] = "v1"
        obj["kind"] = "List"


example = ConfigGroup(
    "example",
    files=["foo.yaml"],
    transformations=[make_service_private, alias, omit_resource],
)
Parameters
  • name (str) – A name for a resource.

  • files (Optional[Sequence[str]]) – Set of paths or a URLs that uniquely identify files.

  • yaml (Optional[Sequence[str]]) – YAML text containing Kubernetes resource definitions.

  • opts (Optional[pulumi.ResourceOptions]) – A bag of optional settings that control a resource’s behavior.

  • pulumi.ResourceOptions], None]]] transformations (Optional[Sequence[Callable[[Any,) – A set of transformations to apply to Kubernetes resource definitions before registering with engine.

  • resource_prefix (Optional[str]) – An optional prefix for the auto-generated resource names. Example: A resource created with resource_prefix=”foo” would produce a resource named “foo-resourceName”.

resources: pulumi.Output[dict] = None

Kubernetes resources contained in this ConfigGroup.

translate_output_property(prop: str) → str

Provides subclasses of Resource an opportunity to translate names of output properties into a format of their choosing before writing those properties to the resource object.

Parameters

prop (str) – A property name.

Returns

A potentially transformed property name.

Return type

str

translate_input_property(prop: str) → str

Provides subclasses of Resource an opportunity to translate names of input properties into a format of their choosing before sending those properties to the Pulumi engine.

Parameters

prop (str) – A property name.

Returns

A potentially transformed property name.

Return type

str

get_resource(group_version_kind: str, name: str, namespace: Optional[str] = None) → pulumi.output.Output[pulumi.resource.CustomResource][pulumi.resource.CustomResource]

get_resource returns a resource defined by a built-in Kubernetes group/version/kind and name. For example: get_resource("apps/v1/Deployment", "nginx")

Parameters
  • group_version_kind (str) – Group/Version/Kind of the resource, e.g., apps/v1/Deployment

  • name (str) – Name of the resource to retrieve

  • namespace (Optional[str]) – Optional namespace of the resource to retrieve

class pulumi_kubernetes.Directory(name: str, directory: str, opts: Optional[pulumi.resource.ResourceOptions] = None, transformations: Optional[Sequence[Callable[[Any, pulumi.resource.ResourceOptions], None]]] = None, resource_prefix: Optional[str] = None)

Directory is a component representing a collection of resources described by a kustomize directory (kustomization).

from pulumi_kubernetes.kustomize import Directory

hello_world = Directory(
    "hello-world-local",
    directory="./helloWorld",
)
from pulumi_kubernetes.kustomize import Directory

hello_world = Directory(
    "hello-world-remote",
    directory="https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
)
from pulumi_kubernetes.helm.v3 import Chart, ChartOpts, FetchOpts

# Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
def make_service_private(obj, opts):
    if obj["kind"] == "Service" and obj["apiVersion"] == "v1":
        try:
            t = obj["spec"]["type"]
            if t == "LoadBalancer":
                obj["spec"]["type"] = "ClusterIP"
        except KeyError:
            pass


# Set a resource alias for a previous name.
def alias(obj, opts):
    if obj["kind"] == "Deployment":
        opts.aliases = ["oldName"]


# Omit a resource from the Chart by transforming the specified resource definition to an empty List.
def omit_resource(obj, opts):
    if obj["kind"] == "Pod" and obj["metadata"]["name"] == "test":
        obj["apiVersion"] = "v1"
        obj["kind"] = "List"


hello_world = Directory(
    "hello-world-remote",
    directory="https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
    transformations=[make_service_private, alias, omit_resource],
)
Parameters
  • name (str) – A name for a resource.

  • directory (str) – The directory containing the kustomization to apply. The value can be a local directory or a folder in a git repository. Example: ./helloWorld Example: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld

  • opts (Optional[pulumi.ResourceOptions]) – A bag of optional settings that control a resource’s behavior.

  • pulumi.ResourceOptions], None]]] transformations (Optional[Sequence[Callable[[Any,) – A set of transformations to apply to Kubernetes resource definitions before registering with engine.

  • resource_prefix (Optional[str]) – An optional prefix for the auto-generated resource names. Example: A resource created with resource_prefix=”foo” would produce a resource named “foo-resourceName”.

resources: pulumi.Output[dict] = None

Kubernetes resources contained in this Directory.

translate_output_property(prop: str) → str

Provides subclasses of Resource an opportunity to translate names of output properties into a format of their choosing before writing those properties to the resource object.

Parameters

prop (str) – A property name.

Returns

A potentially transformed property name.

Return type

str

translate_input_property(prop: str) → str

Provides subclasses of Resource an opportunity to translate names of input properties into a format of their choosing before sending those properties to the Pulumi engine.

Parameters

prop (str) – A property name.

Returns

A potentially transformed property name.

Return type

str

get_resource(group_version_kind: str, name: str, namespace: Optional[str] = None) → pulumi.output.Output[pulumi.resource.CustomResource][pulumi.resource.CustomResource]

get_resource returns a resource defined by a built-in Kubernetes group/version/kind and name. For example: get_resource("apps/v1/Deployment", "nginx")

Parameters
  • group_version_kind (str) – Group/Version/Kind of the resource, e.g., apps/v1/Deployment

  • name (str) – Name of the resource to retrieve

  • namespace (Optional[str]) – Optional namespace of the resource to retrieve

class pulumi_kubernetes.Provider(resource_name: str, opts: Optional[pulumi.resource.ResourceOptions] = None, cluster: Union[str, Awaitable[str], Output[T], None] = None, context: Union[str, Awaitable[str], Output[T], None] = None, enable_dry_run: Union[bool, Awaitable[bool], Output[T], None] = None, kubeconfig: Union[str, Awaitable[str], Output[T], None] = None, namespace: Union[str, Awaitable[str], Output[T], None] = None, render_yaml_to_directory: Union[str, Awaitable[str], Output[T], None] = None, suppress_deprecation_warnings: Union[bool, Awaitable[bool], Output[T], None] = None, __props__=None, __name__=None, __opts__=None)

The provider type for the kubernetes package.

Parameters
  • resource_name (str) – The name of the resource.

  • opts (pulumi.ResourceOptions) – Options for the resource.

  • cluster (pulumi.Input[str]) – If present, the name of the kubeconfig cluster to use.

  • context (pulumi.Input[str]) – If present, the name of the kubeconfig context to use.

  • enable_dry_run (pulumi.Input[bool]) – BETA FEATURE - If present and set to true, enable server-side diff calculations. This feature is in developer preview, and is disabled by default.

This config can be specified in the following ways, using this precedence:
1. This `enableDryRun` parameter.
2. The `PULUMI_K8S_ENABLE_DRY_RUN` environment variable.
Parameters
  • kubeconfig (pulumi.Input[str]) – The contents of a kubeconfig file or the path to a kubeconfig file. If this is set, this config will be used instead of $KUBECONFIG.

  • namespace (pulumi.Input[str]) – If present, the default namespace to use. This flag is ignored for cluster-scoped resources.

A namespace can be specified in multiple places, and the precedence is as follows:
1. `.metadata.namespace` set on the resource.
2. This `namespace` parameter.
3. `namespace` set for the active context in the kubeconfig.
Parameters

render_yaml_to_directory (pulumi.Input[str]) – BETA FEATURE - If present, render resource manifests to this directory. In this mode, resources will not be created on a Kubernetes cluster, but the rendered manifests will be kept in sync with changes to the Pulumi program. This feature is in developer preview, and is disabled by default.

Note that some computed Outputs such as status fields will not be populated
since the resources are not created on a Kubernetes cluster. These Output values will remain undefined,
and may result in an error if they are referenced by other resources. Also note that any secret values
used in these resources will be rendered in plaintext to the resulting YAML.
Parameters

suppress_deprecation_warnings (pulumi.Input[bool]) – If present and set to true, suppress apiVersion deprecation warnings from the CLI.

This config can be specified in the following ways, using this precedence:
1. This `suppressDeprecationWarnings` parameter.
2. The `PULUMI_K8S_SUPPRESS_DEPRECATION_WARNINGS` environment variable.
translate_output_property(prop)

Provides subclasses of Resource an opportunity to translate names of output properties into a format of their choosing before writing those properties to the resource object.

Parameters

prop (str) – A property name.

Returns

A potentially transformed property name.

Return type

str

translate_input_property(prop)

Provides subclasses of Resource an opportunity to translate names of input properties into a format of their choosing before sending those properties to the Pulumi engine.

Parameters

prop (str) – A property name.

Returns

A potentially transformed property name.

Return type

str