Back to Prefect

credentials

docs/integrations/prefect-kubernetes/api-ref/prefect_kubernetes-credentials.mdx

3.6.30.dev34.5 KB
Original Source

prefect_kubernetes.credentials

Module for defining Kubernetes credential handling and client generation.

Classes

KubernetesClusterConfig <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/credentials.py#L34" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Stores configuration for interaction with Kubernetes clusters.

See from_file for creation.

Attributes:

  • config: The entire loaded YAML contents of a kubectl config file
  • context_name: The name of the kubectl context to use

Methods:

configure_client <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/credentials.py#L116" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
configure_client(self) -> None

Activates this cluster configuration by loading the configuration into the Kubernetes Python client. After calling this, Kubernetes API clients can use this config's context.

from_file <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/credentials.py#L71" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
from_file(cls: Type[Self], path: Optional[Path] = None, context_name: Optional[str] = None) -> Self

Create a cluster config from the a Kubernetes config file.

By default, the current context in the default Kubernetes config file will be used.

An alternative file or context may be specified.

The entire config file will be loaded and stored.

get_api_client <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/credentials.py#L108" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
get_api_client(self) -> 'ApiClient'

Returns a Kubernetes API client for this cluster config.

parse_yaml_config <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/credentials.py#L65" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
parse_yaml_config(cls, value)

KubernetesCredentials <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/credentials.py#L127" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Credentials block for generating configured Kubernetes API clients.

Attributes:

  • cluster_config: A KubernetesClusterConfig block holding a JSON kube config for a specific kubernetes context.

Methods:

get_client <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/credentials.py#L150" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
get_client(self, client_type: Literal['apps', 'batch', 'core', 'custom_objects'], configuration: Optional[Configuration] = None) -> AsyncGenerator[KubernetesClient, None]

Convenience method for retrieving a Kubernetes API client for deployment resources.

Args:

  • client_type: The resource-specific type of Kubernetes client to retrieve.

get_resource_specific_client <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-kubernetes/prefect_kubernetes/credentials.py#L200" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
get_resource_specific_client(self, client_type: str, api_client: ApiClient) -> Union[AppsV1Api, BatchV1Api, CoreV1Api]

Utility function for configuring a generic Kubernetes client. It will attempt to connect to a Kubernetes cluster in three steps with the first successful connection attempt becoming the mode of communication with a cluster:

  1. It will first attempt to use a KubernetesCredentials block's cluster_config to configure a client using KubernetesClusterConfig.configure_client.

  2. Attempt in-cluster connection (will only work when running on a pod).

  3. Attempt out-of-cluster connection using the default location for a kube config file.

Args:

  • client_type: The Kubernetes API client type for interacting with specific Kubernetes resources.

Returns:

  • An authenticated, resource-specific Kubernetes Client.

Raises:

  • ValueError: If client_type is not a valid Kubernetes API client type.