Skip to content

borisputerka-zz/updatecontext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubectl updatecontext

GitHub Release Go Report Card

Kubectl plugin that manages kubernetes contexts. It will create context in <namespace/<cluster> format. Contexts for non-existent namespaces will be deleted (e.g., after you delete namespace with created context).

To switch contexts you can use kubectx or fzf (see instructions below). Once you have contexts created you will no longer need to use kubectx with kubens when accessing namespace in different cluster.

Installation and usage

Info: This plugin is not in krew-index but for convenience I added krew manifest as installlation option..

  1. Install plugin

    • using krew manifest in this repository
      $ kubectl krew install --manifest=deploy/krew/plugin.yaml
      

    or

    • using Makefile
      $ make bin
      
  2. Use plugin

    $ kubectl updatecontext
    

Use fzf to switch contexts

Add these lines into your .bashrc or .zshrc

#fzf inline alias
alias _inline_fzf="fzf --multi --ansi -i -1 --height=50% --reverse -0 --header-lines=1 --inline-info --border"

#kubernetes contexts switcher
kcs() {
    local context="$(kubectl config get-contexts | _inline_fzf | awk '{print $1}')"
    eval kubectl config set current-context "${context}"
}

Now use kcs within your terminal.

$ kcs