Home > Software design >  Kubernetes - show help for a command but only show examples
Kubernetes - show help for a command but only show examples

Time:10-28

Is it possible to get the help for a k8s command but only show the Examples section of the help?

For example, if I run:

kubectl run --help

It outputs different sections, but I only want to see examples on the screen.

CodePudding user response:

This command only show line 2 to line 30

kubectl run --help | head -n30 | tail -n28

CodePudding user response:

Like many other help pages, K8s help docs come in this order:

  1. Description
  2. Examples
  3. Options
  4. Usage

you could use sed to cut out the part you need:

kubectl run --help | sed -n "/Examples:/,/Options:/p"

or better:

kubectl run --help | sed -n "/Examples:/,/Options:/p" | grep -v "Options:"
  • Related