How would you write a list of Kubernetes namespaces to a file? Each namespace should be on a separate line and there should be no header.

Experience Level: Senior
Tags: Kubernetes

Answer

Run the following command:

kubectl get ns -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' > ~/filename.txt

Comments

No Comments Yet.
Be the first to tell us what you think.
Kubernetes Certified Application Developer (CKAD) preparation
Kubernetes Certified Application Developer (CKAD) preparation

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself
Kubernetes
Kubernetes

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself
Kubernetes Certified Administrator (CKA) preparation
Kubernetes Certified Administrator (CKA) preparation

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself