Skip to main content

prefect_kubernetes.credentials

Module for defining Kubernetes credential handling and client generation.

Classes

KubernetesClusterConfig

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

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

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

get_api_client(self) -> 'ApiClient'
Returns a Kubernetes API client for this cluster config.

parse_yaml_config

parse_yaml_config(cls, value)

KubernetesCredentials

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

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

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.