はじめに
kubectlのプラグインを管理できるKrewについて紹介していきます。
Krewとは
Krewは、kubectlコマンドのプラグインマネージャーになります。
kubectlのプラグインの検索やインストール、アップデートが楽にできるようになります。
インストール
Krewをインストールします。
インストールするコマンドは下記の通りです。brew
でもインストール可能ですが、公式ドキュメントによると今のところはサポートしていないということです。
(
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
)
インストールが完了したら、下記を.bashrc
や.zshrc
などに追記します。
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
使い方
簡単に使い方を紹介します。
プラグインリストの更新
kubectl krew update
プラグインの検索
kubectl krew search
❯ 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
...
プラグインのインストール
kubectl krew install <plugin name>
❯ kubectl krew install resource-capacity
Updated the local copy of plugin index.
Installing plugin: resource-capacity
Installed plugin: resource-capacity
\
| Use this plugin:
| kubectl resource-capacity
| Documentation:
| https://github.com/robscott/kube-capacity
/
WARNING: You installed plugin "resource-capacity" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
インストール済みのプラグインの更新
kubectl krew upgrade
インストール済みのプラグインリスト
kubectl krew list
❯ kubectl krew list
PLUGIN VERSION
krew v0.4.3
resource-capacity v0.7.0