Skip to content

sunny0826/kubecm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0b6a9e2 · Oct 21, 2020
Oct 21, 2020
Oct 21, 2020
Jan 20, 2020
Jan 27, 2020
Nov 26, 2019
Jul 23, 2019
Aug 5, 2020
Oct 21, 2020
Oct 21, 2020
Aug 19, 2020
Jan 17, 2020

Repository files navigation

English | 简体中文

KubeCM

Build Status Go Report Card GitHub GitHub release

KubeConfig Manager
 _          _
| | ___   _| |__   ___  ___ _ __ ___
| |/ / | | | '_ \ / _ \/ __| '_ \ _ \
|   <| |_| | |_) |  __/ (__| | | | | |
|_|\_\\__,_|_.__/ \___|\___|_| |_| |_|

Find more information at: https://github.com/sunny0826/kubecm

Usage:
  kubecm [flags]
  kubecm [command]

Available Commands:
    add         Merge configuration file with $HOME/.kube/config
    alias       Generate alias for all contexts
    completion  Generates bash/zsh completion scripts
    delete      Delete the specified context from the kubeconfig
    help        Help about any command
    ls          List kubeconfig
    merge       Merge the kubeconfig files in the specified directory
    namespace   Switch or change namespace interactively
    rename      Rename the contexts of kubeconfig
    switch      Switch Kube Context interactively
    version     Print version info


Flags:
      --config string   path of kubeconfig (default "$HOME/.kube/config")
  -h, --help   help for kubecm

Use "kubecm [command] --help" for more information about a command.

Quick Start

Install

Homebrew

brew install sunny0826/tap/kubecm

Download the binary

GitHub release

# linux x86_64
curl -Lo kubecm.tar.gz https://github.com/sunny0826/kubecm/releases/download/v${VERSION}/kubecm_${VERSION}_Linux_x86_64.tar.gz
# macos
curl -Lo kubecm.tar.gz https://github.com/sunny0826/kubecm/releases/download/v${VERSION}/kubecm_${VERSION}_Darwin_x86_64.tar.gz
# windows
curl -Lo kubecm.tar.gz https://github.com/sunny0826/kubecm/releases/download/v${VERSION}/kubecm_${VERSION}_Windows_x86_64.tar.gz

# linux & macos
tar -zxvf kubecm.tar.gz kubecm
cd kubecm
sudo mv kubecm /usr/local/bin/

# windows
# Unzip kubecm.tar.gz
# Add the binary in to your $PATH

Auto-Completion

bash

# bash
kubecm completion bash > ~/.kube/kubecm.bash.inc
printf "
# kubecm shell completion
source '$HOME/.kube/kubecm.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile

zsh

# add to $HOME/.zshrc 
source <(kubecm completion zsh)
# or
kubecm completion zsh > "${fpath[1]}/_kubecm"

Interactive operation

Interactive

List Kube Context

# List all the contexts in your kubeconfig file
kubecm ls
# Aliases
kubecm l

Generate alias

Generate alias for all contexts.

$ kubecm alias
# dev 
alias k-dev='kubectl --context dev'
# test
alias k-test='kubectl --context test'
# prod
alias k-prod='kubectl --context prod'
$ kubecm alias -o zsh
# add alias context to ~/.zshrc
$ kubecm alias -o bash
# add alias context to ~/.bash_profile

Add configuration to $HOME/.kube/config

# Merge example.yaml with $HOME/.kube/config.yaml
kubecm add -f example.yaml 

# Merge example.yaml and name contexts test with $HOME/.kube/config.yaml
kubecm add -f example.yaml -n test

# Overwrite the original kubeconfig file
kubecm add -f example.yaml -c

Merge the kubeconfig

# Merge kubeconfig in the directory
kubecm merge -f dir

# Merge kubeconfig in the directory and overwrite the original kubeconfig file
kubecm merge -f dir -c

Switch Kube Context interactively

# Switch Kube Context interactively
kubecm switch

switch

Delete context

# Delete the context interactively
kubecm delete
# Delete the context
kubecm delete my-context

Rename context

# Renamed the context interactively
kubecm rename

Switch namespace

You can switch namespace or switch namespace interactively

# Switch Namespace interactively
kubecm namespace
# or
kubecm ns
# change to namespace of kube-system
kubecm ns kube-system

ns

Video

Contribute

Feel free to open issues and pull requests. Any feedback is highly appreciated!

Thanks

JetBrains logo