Skip to main content

Overview

The NamespacedResource class extends the Resource class to provide functionality specific to namespaced resources. Most Kubernetes resources (Pods, Deployments, Services, etc.) are namespaced and inherit from this class.

Class Definition

Constructor

NamespacedResource accepts all parameters from the Resource base class, plus:
str | None
required
Resource name
str | None
required
Namespace where the resource will be created
DynamicClient | None
Dynamic client for connecting to a remote cluster
bool
default:"True"
Indicates if this resource should be deleted on cleanup
str | None
Path to YAML file for the resource
int
default:"TIMEOUT_4MINUTES"
Timeout in seconds for delete operations
bool
default:"False"
Whether to check if the resource exists when initializing, raise if not

Methods

get (class method)

Get namespaced resources from the cluster.
DynamicClient | None
Kubernetes client
str
Namespace to search in (passed as kwarg)
str
default:"''"
Resource kind in lowercase for disambiguation
bool
default:"False"
If True, return raw ResourceInstance objects
Returns: Generator of namespaced resource objects

Properties

instance

Get the current resource instance from the cluster. Overrides the base Resource.instance property to include namespace in the API call.

Inherited Methods

NamespacedResource inherits all methods from Resource, including:
  • create() - Create the resource
  • delete() - Delete the resource
  • update() - Update the resource
  • update_replace() - Replace the resource
  • wait() - Wait for resource to exist
  • wait_deleted() - Wait for resource deletion
  • wait_for_status() - Wait for specific status
  • wait_for_condition() - Wait for specific condition
  • validate() - Validate against schema

Examples

Creating a Namespaced Resource

Listing Resources in a Namespace

Listing Resources Across All Namespaces

Using with Context Manager

Checking if Resource Exists

Working with Resource from YAML

Common Namespaced Resources

Resources that inherit from NamespacedResource include:
  • Pod - Container workloads
  • Deployment - Deployment management
  • Service - Service networking
  • ConfigMap - Configuration data
  • Secret - Sensitive data
  • ReplicaSet - Pod replica management
  • StatefulSet - Stateful workloads
  • Job - Batch workloads
  • CronJob - Scheduled workloads
  • And many more…

See Also