목적
krew는 kubectl 명령어 도구의 플러그인입니다. 그리고 현재 208개의 플러그인이 배포되어 있어서 필요한 플러그인을 찾아 설치해서 유용하게 사용할 수 있습니다.
krew 명령어를 설치하면 아래 결과처럼 플러그인 확인이 가능합니다.
$ kubectl krew search
NAME DESCRIPTION INSTALLED
access-matrix Show an RBAC access matrix for server resources no
accurate Manage Accurate, a multi-tenancy controller no
advise-policy Suggests PodSecurityPolicies and OPA Policies f... no
advise-psp Suggests PodSecurityPolicies for cluster. no
allctx Run commands on contexts in your kubeconfig no
apparmor-manager Manage AppArmor profiles for cluster. no
applier Apply 'go text/template' files on k8s. no
assert Assert Kubernetes resources no
auth-proxy Authentication proxy to a pod or service no
aws-auth Manage aws-auth ConfigMap no
azad-proxy Generate and handle authentication for azad-kub... no
bd-xray Run Black Duck Image Scans no
blame Show who edited resource fields. no
bulk-action Do bulk actions on Kubernetes resources. no
ca-cert Print the PEM CA certificate of the current clu... no
capture Triggers a Sysdig capture to troubleshoot the r... no
cert-manager Manage cert-manager resources inside your cluster no
change-ns View or change the current namespace via kubectl. no
cilium Easily interact with Cilium agents. no
cluster-group Exec commands across a group of contexts. no
clusternet Wrap multiple kubectl calls to Clusternet no
cm Provides commands for OCM/MCE/ACM. no
cnpg Manage your CloudNativePG clusters no
colorize-applied Colorize results of apply/dry-run no
config-cleanup Automatically clean up your kubeconfig no
config-registry Switch between registered kubeconfigs no
confirm Dry-run / diff / confirm before running a command no
cost View cluster cost information no
count Count resources by kind no
creyaml Generate custom resource YAML manifest no
ctx Switch between contexts in your kubeconfig yes
...
....
Shell
우선 krew를 설치하기 위해서 아래 명령어를 터미널에서 수행합니다.
$ (
> set -x; cd "$(mktemp -d)" &&
> OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
> ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
> KREW="krew-${OS}_${ARCH}" &&
> curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
> tar zxvf "${KREW}.tar.gz" &&
> ./"${KREW}" install krew
> )
Shell
출력 결과
++ mktemp -d
+ cd /tmp/tmp.n40b3Ro4Fm
++ uname
++ tr '[:upper:]' '[:lower:]'
+ OS=linux
++ uname -m
++ sed -e s/x86_64/amd64/ -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/'
+ ARCH=amd64
+ KREW=krew-linux_amd64
+ curl -fsSLO https://github.com/kubernetes-sigs/krew/releases/latest/download/krew-linux_amd64.tar.gz
+ tar zxvf krew-linux_amd64.tar.gz
./LICENSE
./krew-linux_amd64
+ ./krew-linux_amd64 install krew
Adding "default" plugin index from https://github.com/kubernetes-sigs/krew-index.git.
Updated the local copy of plugin index.
Installing plugin: krew
Installed plugin: krew
\
| Use this plugin:
| kubectl krew
| Documentation:
| https://krew.sigs.k8s.io/
| Caveats:
| \
| | krew is now installed! To start using kubectl plugins, you need to add
| | krew's installation directory to your PATH:
| |
| | * macOS/Linux:
| | - Add the following to your ~/.bashrc or ~/.zshrc:
| | export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
| | - Restart your shell.
| |
| | * Windows: Add %USERPROFILE%\.krew\bin to your PATH environment variable
| |
| | To list krew commands and to get help, run:
| | $ kubectl krew
| | For a full list of available plugins, run:
| | $ kubectl krew search
| |
| | You can find documentation at
| | https://krew.sigs.k8s.io/docs/user-guide/quickstart/.
| /
/
Shell
이후 .bashrc 파일에 PATH 설정을 하고 적용합니다.
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
$ source .bashrc
Shell
$ kubectl krew
krew is the kubectl plugin manager.
You can invoke krew through kubectl: "kubectl krew [command]..."
Usage:
kubectl krew [command]
Available Commands:
completion generate the autocompletion script for the specified shell
help Help about any command
index Manage custom plugin indexes
info Show information about an available plugin
install Install kubectl plugins
list List installed kubectl plugins
search Discover kubectl plugins
uninstall Uninstall plugins
update Update the local copy of the plugin index
upgrade Upgrade installed plugins to newer versions
version Show krew version and diagnostics
Flags:
-h, --help help for krew
-v, --v Level number for the log level verbosity
Use "kubectl krew [command] --help" for more information about a command.
Shell
여기까지 krew를 설치했고 kubectx와 kubens를 설치해 보겠습니다.
$ kubectl krew install ctx
Updated the local copy of plugin index.
Installing plugin: ctx
Installed plugin: ctx
\
| Use this plugin:
| kubectl ctx
| Documentation:
| https://github.com/ahmetb/kubectx
| Caveats:
| \
| | If fzf is installed on your machine, you can interactively choose
| | between the entries using the arrow keys, or by fuzzy searching
| | as you type.
| | See https://github.com/ahmetb/kubectx for customization and details.
| /
/
WARNING: You installed plugin "ctx" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
Shell
이제 설치된 ctx 명령을 통해서 kubernetes context 내용을 조회할 수 있습니다.
(kubectl config get-contexts 명령어와 동일한 기능입니다.)
$ kubectl ctx
arn:aws:eks:ap-northeast-2:2:cluster/dev-eks
docker-desktop
Shell
만약에 context를 변경하고 싶다면 아래의 명령을 수행하면 됩니다.
$ kubectl ctx docker-desktop
Switched to context "docker-desktop".
Shell
이후 .bashrc 파일에 PATH 설정을 하고 적용합니다.
alias kubectx='kubectl ctx'
$ source .bashrc
Shell
이제 kubens 플러그인을 설치해 보겠습니다.
$ kubectl krew install ns
Updated the local copy of plugin index.
Installing plugin: ns
Installed plugin: ns
\
| Use this plugin:
| kubectl ns
| Documentation:
| https://github.com/ahmetb/kubectx
| Caveats:
| \
| | If fzf is installed on your machine, you can interactively choose
| | between the entries using the arrow keys, or by fuzzy searching
| | as you type.
| /
/
WARNING: You installed plugin "ns" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
Shell
이제 현재 context에 생성된 namespace 내용을 조회할 수 있습니다.
(kubectl get namespace 명령어와 동일합니다.)
$ kubectl ns
cert-manager
david
default
kube-node-lease
kube-public
kube-system
mongodb-pv
redis
Shell
이제 default namespace에서 다른 namespace로 간편하게 변경할 수 있게 되었습니다.
$ kubectl ns redis
Context "arn:aws:eks:ap-northeast-2:144579678262:cluster/dev-eks" modified.
Active namespace is "redis".
Shell
이후 .bashrc 파일에 PATH 설정을 하고 적용합니다.
alias kubens='kubectl ns'
$ source .bashrc
Shell