CodeBlanks Logo Icon CodeBlanks

kubectl get namespaces

Learn to list Namespaces.

kubectl get namespaces

Every cluster comes with a few ready namespaces:

  • default: objects with no namespace specified.
  • kube-system: Kubernetes's own components.
  • kube-public: small data readable by everyone.
  • kube-node-lease: the nodes' liveness signals.
$ kubectl get namespaces
NAME              STATUS   AGE
default           Active   12d
kube-node-lease   Active   12d
kube-public       Active   12d
kube-system       Active   12d

Searching all namespaces

-A (--all-namespaces) lists a type in all namespaces; a NAMESPACE column is added to the output. If you don't know which namespace an object is in, it's the fastest way:

$ kubectl get deploy -A
NAMESPACE     NAME      READY   UP-TO-DATE   AVAILABLE
dev           web       1/1     1            1
prod          web       3/3     3            3
kube-system   coredns   2/2     2            2

Practice Scan the namespaces

Write two commands: list the namespaces; list the deployments in all namespaces.

Starter code

terminal
# buraya yaz

Sample solution

terminal
kubectl get namespaces
kubectl get deployments -A

Expected output

NAME              STATUS   AGE
default           Active   12d
dev               Active   3d
kube-system       Active   12d
NAMESPACE     NAME      READY   UP-TO-DATE   AVAILABLE   AGE
dev           web       1/1     1            1           3d
kube-system   coredns   2/2     2            2           12d

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Why isn't installing your own applications in kube-system recommended?

  • Pods don't run there
  • It's slower
  • They mix with system components; something critical may be changed by mistake Correct answer
  • It's forbidden

Explanation: Applications are kept in their own namespaces.

2 List the namespaces using the abbreviation.

Question
kubectl get ____
Answer
kubectl get ns

Explanation: ns is the abbreviation of namespaces.

3 Match.

Term Meaning
default Unspecified ones
kube-system System components
kube-node-lease Node liveness
-A All namespaces

All lessons in Intermediate