Get Namespaces
Displays all the namespaces in your Kubernetes cluster.
Usage:
Use these commands to list all available namespaces. 'ns' is a shorthand for 'namespaces'.
Get Pods from Default Namespace
Lists all pods in the default namespace.
Note:
If no namespace is specified, kubectl uses the default namespace.
Get Pods from Specific Namespace
Lists all pods in the specified namespace.
Usage:
Use these commands to get pods from a specific namespace. '-n' is a shorthand for '--namespace'.
Change Current Namespace
Changes the default namespace for the current context.
Example:
After running this command, all subsequent kubectl commands will use the kube-system namespace by default.
Change Back to Default Namespace
Reverts the default namespace back to 'default'.
Usage:
Use this command to switch back to the default namespace after working in another namespace.
Create Namespace
Creates a new namespace with the specified name.
Example:
This command creates a namespace named "hello".
Verify Namespace Creation
Lists all namespaces to verify the new namespace was created successfully.
Usage:
After creating a namespace, use this command to confirm it appears in the list of all namespaces.
Delete Namespace
Deletes the specified namespace and all resources within it.
Warning:
This command will delete the namespace and all resources contained within it. Use with caution.
About Kubernetes Namespaces
What is a Namespace?
A namespace in Kubernetes is a way to divide cluster resources between multiple users, teams, or applications. It provides a scope for names and helps organize resources in a cluster.
Namespaces are a powerful feature for implementing multi-tenancy in Kubernetes clusters, allowing different teams to share the same cluster without interfering with each other.
Common Use Cases
- Separating development, staging, and production environments
- Isolating different teams or projects within the same cluster
- Implementing resource quotas for different applications
- Managing access control with RBAC (Role-Based Access Control)
Default Namespaces
Kubernetes comes with several built-in namespaces:
- default: The default namespace for objects with no other namespace
- kube-system: The namespace for objects created by the Kubernetes system
- kube-public: A namespace that is readable by all users
- kube-node-lease: A namespace for node lease objects