Kubernetes

[kubectl] krew - Kubernetes Plugin Manager

seulseul 2023. 7. 10. 17:41

쿠버네티스 플러그인 관리자 - Krew

Krew는 쿠버네티스 플러그인 패키지 관리자입니다.

macOS의 brew, Ubuntu의 apt 와 비슷한 역할을 수행한다고 보면 됩니다.

 

Krew 를 통해 현재 217개이상의 플러그인을 설치할 수 있으며, 사용법도 매우 단순하다. 

krew 의 주요기능은 다음과 같다.

  • 플러그인 검색
  • 플러그인 설치
  • 플러그인 업데이트

 

Installing

krew 설치 방법

# macOS & Linux
# git 이 설치되어 있어야합니다.
# () 부분도 포함하여 붙여 넣습니다.
(
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
)
# Krew 실행파일 위치를 PATH에 등록
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
# Shell을 재시작
source ~/.zshhrc # bash 을 사용하는 경우, bashrc를 입력
# 정상적으로 설치되었는지 확인 & krew 업데이트
kubectl krew update

Krew 삭제

# Krew 삭제
rm -rf -- ~/.krew

 

Krew 사용법

Krew는 일반적인 패키지 관리자가 수행하는 역할을 대부분 수행할 수 있습니다.

 

1. 플러그인 리스트 업데이트

kubectl krew update

2. 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
~
~
~

 

 

3. 플러그인 설치

# kubectl krew install <plugin-name>
$ kubectl krew install konfig
# -----
➜ ~ kubectl krew install konfig
Updated the local copy of plugin index.
Installing plugin: konfig
Installed plugin: konfig
\
| Use this plugin:
| kubectl konfig
| Documentation:
| https://github.com/corneliusweig/konfig
/

4. 플러그인 사용

# kubectl krew <plugin-name>
# 정상적으로 설치 되었는지 확인
$ kubectl konfig
# -------------------------------------
➜ ~ kubectl konfig
kubectl konfig helps to merge, split or import kubeconfig files
USAGE:
kubectl konfig merge [--preserve-structure,-p] <CONFIG>..
Merge multiple kubeconfigs into one.
-p prevents flattening which will make the result less portable.
kubectl konfig import [--preserve-structure,-p] [--save,-s] [--stdin,-i] <CONFIG>..
Import the given configs into your current kubeconfig (respects KUBECONFIG env var).
-s writes the result to your ~/.kube/config
-i import kubeconfig string from stdin
kubectl konfig split <CONTEXT>.. [--kubeconfig,-k <CONFIG>]
kubectl konfig export <CONTEXT>.. [--kubeconfig,-k <CONFIG>]
Export/split off a minimal kubeconfig with the given contexts
-k may be repeated or contain a comma-delimited list of input configs.
When omitted, export from the default kubeconfig.
EXAMPLES:
Merge new-cfg with your current kubeconfig
$ kubectl konfig import new-cfg
and save the result to ~/.kube/config
$ kubectl konfig import --save new-cfg
CAVEAT: due to how shells work, the following will lose your current ~/.kube/config
WRONG $ kubectl konfig import new-cfg > ~/.kube/config
Export ctx1 and ctx2 into combined.yaml
$ kubectl konfig export -k ~/.kube/config -k k3s.yaml ctx1 ctx2 > combined.yaml
Merge two configs
$ kubectl konfig merge ~/.kube/config k3s.yaml > merged-and-flattened
or
$ kubectl konfig merge -p ~/.kube/config k3s.yaml > merged-not-flattened

 

# kubeconfig 추출하기 (export)
# kubectl konfig export {context-name} > {파일명}
kubectl konfig export kind-kind > kind.config

5. 플러그인 삭제

kubectl krew uninstall konfig

 

 

More Plugin

Krew 를 이용하여 설치 할 수 있는 플러그인은 여기서 확인할 수 있습니다.