Skip to main content
Namespaced resources are Kubernetes objects that exist within a specific namespace. The NamespacedResource class extends the base Resource class to provide namespace-aware functionality.

Overview

Most Kubernetes resources are namespaced, meaning they exist within a namespace scope and are isolated from resources in other namespaces. Common examples include Pods, Deployments, Services, ConfigMaps, and Secrets.

NamespacedResource Class

The NamespacedResource class is defined in /home/daytona/workspace/source/ocp_resources/resource.py:1598 and provides:
  • Namespace requirement enforcement
  • Namespace-aware API operations
  • Automatic namespace handling from YAML/dict inputs

Creating Namespaced Resources

Basic Creation

Namespaced resources require both name and namespace parameters. Omitting either will raise a MissingRequiredArgumentError.

From YAML with Namespace

Override Namespace from YAML

Common Namespaced Resources

Here are the most commonly used namespaced resources:

Workload Resources

Configuration Resources

Network Resources

Storage Resources

RBAC Resources

Querying Namespaced Resources

Get Resources in Specific Namespace

Get Resources Across All Namespaces

Get Single Resource

Namespace Management

Check Resource Namespace

Ensure Namespace Exists

Create Multiple Resources in Same Namespace

Differences from Cluster Resources

Namespaced Resources: Require namespace parameter
Cluster Resources: No namespace parameter
Namespaced Resources: API calls include namespace
Cluster Resources: API calls are cluster-wide
Namespaced Resources: Deleted with namespace or individually
Cluster Resources: Only individually deleted
Namespaced Resources: Can use namespace-scoped RBAC (Role/RoleBinding)Cluster Resources: Require cluster-scoped RBAC (ClusterRole/ClusterRoleBinding)

Common Patterns

Pattern 1: Create App with Multiple Resources

Pattern 2: Resource with Namespace Context

Pattern 3: Batch Resource Creation

Troubleshooting

Missing Namespace Error

Namespace Not Found

Check Namespace Before Creating Resource

Best Practices

Always Specify Namespace

Explicitly provide the namespace parameter for all namespaced resources to avoid confusion.

Use Namespace Context Managers

When creating multiple resources in the same namespace, use context managers for automatic cleanup.

Verify Namespace Exists

Check if the namespace exists before creating resources in it, or create it as part of your setup.

Label Your Resources

Use consistent labels across resources in a namespace for easier querying and management.

Next Steps

Context Managers

Learn about automatic resource lifecycle management

Resource Class

Understand the base Resource class

Working with Pods

Complete guide to working with pods

Working with Deployments

Manage deployments and replicas