Working with Namespace
Estimated time to read: 3 minutes
Namespaces are a native way to divide a single Kubernetes cluster into multiple virtual clusters.
-
Run the following command to list all Kubernetes API resources
-
Namespaces a good way of sharing a single cluster among different departments and environments. For example,
-
A single cluster might have the following Namespaces.
- Dev
- Test
- QA
Creating Namespaces
-
Imperatively
-
Run the following command to create namespace called
opsfulsionlabs
Declaratively
-
Run the following command to create namespace called
opsfulsionlabs
Namespace/ofl-namespace.yml -
Auto Generate Namespace
-
Ns mainfest file in YML
-
Ns mainfest file in JSON
-
Inspecting Namespaces
-
Run the following command to list all namespaces
-
Run the following command to describe namespaces
Deleting Namespace
-
Imperatively
-
Run the following command to delete namespaces
-
-
Declaratively
-
Run the following command to delete namespaces
-
Set New Default Namespace
When you start using Namespaces, you’ll quickly realize it’s painful remembering to add the -n
or --namespace
flag on all kubectl
commands. A better way might be to set your kubeconfig
to automatically work with a particular Namespace.
-
Run the following command to change namespaces default to opsfusionlabs
-
Run the following command to list the objects in opsfusionlabs namespace
Mapping Objects in Specific Namespace
-
Imperatively
-
Run the following command to create nginx pod in
opsfusionlabs
namespace
-
-
Declaratively
-
Run the following command to create nginx pod in
opsfusionlabs
namespace
-
Clean up
-
Run the following command to clear all deployment in cluster