Overview
TheNamespacedResource 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
Properties
instance
Inherited Methods
NamespacedResource inherits all methods from Resource, including:create()- Create the resourcedelete()- Delete the resourceupdate()- Update the resourceupdate_replace()- Replace the resourcewait()- Wait for resource to existwait_deleted()- Wait for resource deletionwait_for_status()- Wait for specific statuswait_for_condition()- Wait for specific conditionvalidate()- 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
- Resource - Base resource class
- Pod - Pod resource
- Deployment - Deployment resource
- Service - Service resource