Skip to content

Latest commit

 

History

History
206 lines (129 loc) · 7.26 KB

kubernetes-tools.md

File metadata and controls

206 lines (129 loc) · 7.26 KB

Kubernetes - Tools, Tips & Tricks

k9s

k9s: Kubernetes CLI To Manage Your Clusters In Style!

k9s demo

Usage

When first opened, k9s show the list of pods.

From the Pods view, you can:

  • Change the selected pod (Up, Down),

    • then doing actions with that selected pod (by pressing the key bindings in blue color), e.g.
      • Describe that pod, by pressing d
      • Logs, show logs of all containers of that pod, by pressing l
      • ...
      • View that selected pod, by pressing Enter
  • Change the namespace (by pressing the key bindings in pink color)

    • to all by pressing 0
    • to default by pressing 1 (by default, k9s use default namespace)
  • Change to another list (resource)

    • List all the resources, by pressing Ctrl +A
    • Change to the view for that resource, by pressing Enter

    for example: change back to the default view - Pods

    • Ctrl + A
      • Downs to select pods (the 2nd one)
      • Enter
    • Press : to enter command mode
      • Type in the command for pod: pod (or any of po,pod,pods,v1/pods - showed in Ctrl + A)
Action Key Binding Command Note
Change the selected resource Up - Down
View (the selected resource) Enter Available for any selected resource
Back Esc
Quit K9s Ctrl + C
Help ? Available at any view, change depend on which view is showing
Show all available resource alias Ctrl + A 1. Up/Down; 2. Enter
(to close the Aliases view: use Ese or press Ctrl + A again)

Headlamp

Headlamp1 (a CNCF Sandbox project2): A Kubernetes web UI that is fully-featured, user-friendly and extensible

Headlamp demo

Tips & Tricks

Use the right version of kubectl for each cluster/project with asdf

You must use a kubectl version that is compatible with your cluster control plane (kube-apiserver).

Why

kubectl is supported within one minor version (older or newer) of kube-apiserver.

e.g.

  • kube-apiserver is at 1.30
  • kubectl is supported at 1.31, 1.30, and 1.29

For more information, see

How?

See the demo at asdf-demo repository

Make aliases for kubectl

Show cluster information in shell prompt

Add shell completions for kubectl

Configuration for completion

Add color to kubectl output with kubecolor

kubecolor colorizes your kubectl command output and does nothing else.

You can use kubecolor as a complete alternative of kubect

kubectl get pods - demo

kubectl describe pod - demo

Configuration
  • zsh

    # .zshrc
    alias k="kubectl"
    
    if [ "$(command -v kubecolor)" ]; then
      alias kubectl="kubecolor"
      compdef kubecolor=kubectl
    fi
  • fish

    # ~/.config/fish/config.fish
    if status is-interactive
      abbr --add k kubectl # https://fishshell.com/docs/current/cmds/abbr.html
    
      if  command -v kubecolor &>/dev/null
          alias kubectl=kubecolor # https://fishshell.com/docs/current/cmds/alias.html
    
          # make kubecolor inherit completions from kubectl # https://fishshell.com/docs/current/cmds/complete.html
          complete -c kubecolor -w kubectl
      end
    end

Switch between contexts (cluster) with kubectx

kubectx: a tool to switch between contexts (clusters) on kubectl faster.

kubectx demo

Switch between namespaces with kubens

kubens: a tool to switch between Kubernetes namespaces (and configure them for kubectl) easily.

kubens demo

Switch between contexts/namspace with kubeswitch

kubeswitch: kubectx for operators, treat clusters as cattle, not pets.

kubeswitch demo

Footnotes

  1. https://github.com/headlamp-k8s/headlamp

  2. https://www.cncf.io/projects/headlamp/