DEV Community

Cover image for kubectl output like a pro
dejanualex
dejanualex

Posted on

6 3

kubectl output like a pro

If your work involves kubectl, even more wrapping kubectl commands in bash scripts, then this might be for you.

Image description

So let's say you want to take only the pods names for all namespaces. You can use things la AWK, grep but also you can customize your output:

kubectl get po -o name -A
Enter fullscreen mode Exit fullscreen mode

Pretty simple, and it looks like this:

pod/harbor-jobservice-5f56f77c85-75fzj
pod/harbor-nginx-858bb8887f-8grwb
pod/harbor-portal-59ff88c985-2k878
pod/harbor-redis-0

If you don't like that fact that pod's names are prefixed with pod/...say no more:

kubectl get po -o=custom-columns=NAME:.metadata.name -A
Enter fullscreen mode Exit fullscreen mode

harbor-jobservice-5f56f77c85-75fzj
harbor-nginx-858bb8887f-8grwb
harbor-portal-59ff88c985-2k878
harbor-redis-0

Would be nice though to know the namespace in which each pod is running:

kubectl get po -A -o go-template='{{range .items}} --> {{.metadata.name}} in namespace: {{.metadata.namespace}}{{"\n"}}{{end}}'
Enter fullscreen mode Exit fullscreen mode

--> harbor-jobservice-5f56f77c85-75fzj in namespace: harbor
--> harbor-nginx-858bb8887f-8grwb in namespace: harbor
--> harbor-portal-59ff88c985-2k878 in namespace: harbor
--> harbor-redis-0 in namespace: harbor

That's about it, also this applies for Docker check this article.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay