The Ops Community ⚙️

Cover image for Must-Know Flags for kubectl describe
Rishabh Jain
Rishabh Jain

Posted on

Must-Know Flags for kubectl describe

The kubectl describe command is an invaluable tool for inspecting the detailed configuration and runtime state of Kubernetes objects like pods, deployments, and services. It is very useful for troubleshooting issues in a Kubernetes cluster.

The describe command works for any Kubernetes object kind such as nodes, namespaces, ingresses, etc. - not just pods. It is commonly combined with grep to extract specific details from the verbose output. Moreover, we can make the describe command even more powerful by passing flags to it in combination with grep.

1) -i flag → The -i flag enables case-insensitive matching for the regular expression pattern.

Syntax

kubectl describe <object_type> <obejct_name> | grep -i "keyword_you_are_searching"
Enter fullscreen mode Exit fullscreen mode

Example

kubectl describe pod pod1 | grep -i "image"
Enter fullscreen mode Exit fullscreen mode

Output
kubectl describe pod pod1 | grep -i "image"

2) -A flag → The -A flag is used to print lines of trailing context after matching lines.

Syntax

kubectl describe <object_type> <obejct_name> | grep -i -A <no_of_lines_you_want_to_print> "keyword_you_are_searching"
Enter fullscreen mode Exit fullscreen mode

Example

kubectl describe pod pod1 | grep -i -A 8 "image"
Enter fullscreen mode Exit fullscreen mode

Output
kubectl describe pod pod1 | grep -i -A 8 "image"

3) -B flag → The -B flag will print lines before the matching lines.

Syntax

kubectl describe <object_type> <obejct_name> | grep -i -B <no_of_lines_you_want_to_print> "keyword_you_are_searching"
Enter fullscreen mode Exit fullscreen mode

Example

kubectl describe pod pod1 | grep -i -B 8 "image"
Enter fullscreen mode Exit fullscreen mode

Output
kubectl describe pod pod1 | grep -i -B 8 "image"

Top comments (1)

Collapse
 
iziodev profile image
Romain Billot

Subject is not about kubectl describe flags, but grep flags instead