Krew est le gestionnaire de plugins pour l'outil de ligne de commande kubectl.
Krew vous aide à :
Il y a 142 plugins kubectl actuellement distribués sur Krew.
Krew aide également les développeurs de plugins kubectl : Vous pouvez empaqueter et distribuer vos plugins sur plusieurs plateformes facilement et les rendre disponibles par le biais d'un référentiel de plugins centralisé avec Krew.
Krew est lui-même un plugin kubectl qui est installé et mis à jour via Krew (oui, Krew s'auto-gére).
Attention:
krew est uniquement compatible avec kubectl v1.12 ou plus.
Note:
Git doit être disponible sur l'environnement
Il suffira simplement de copier/coller le code ci-dessous pour installer 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/')" && curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" && tar zxvf krew.tar.gz && KREW=./krew-"${OS}_${ARCH}" && "$KREW" install krew )
Nous allons installer krew sur notre serveur bastion.
bastion:~$ ( > 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/')" && > curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" && > tar zxvf krew.tar.gz && > KREW=./krew-"${OS}_${ARCH}" && > "$KREW" install krew > ) ++ mktemp -d + cd /tmp/tmp.T5ZEwsg5MP ++ 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 + curl -fsSLO https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz + tar zxvf krew.tar.gz ./LICENSE ./krew-darwin_amd64 ./krew-darwin_arm64 ./krew-linux_amd64 ./krew-linux_arm ./krew-linux_arm64 ./krew-windows_amd64.exe + KREW=./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/. | / /
Ajoutez le répertoire '$HOME/.krew/bin' à votre variable d'environnement PATH. Pour ce faire, mettez à jour votre fichier .bashrc ou .zshrc et ajoutez la ligne suivante :
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
On resource notre bash et on vérifie notre installation
bastion:~$ exec bash bastion:~$ kubectl krew krew is the kubectl plugin manager. You can invoke krew through kubectl: "kubectl krew [command]..." Usage: kubectl krew [command] Available Commands: 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.
Tout d'abord, avant de pouvoir utiliser krew, nous allons mettre à jour la base local
bastion:~$ kubectl krew update Updated the local copy of plugin index.
Pour découvrir la liste des plugins disponible
bastion:~$ kubectl krew search NAME DESCRIPTION INSTALLED access-matrix Show an RBAC access matrix for server resources 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 assert Assert Kubernetes resources no auth-proxy Authentication proxy to a pod or service no azad-proxy Generate and handle authentication for azad-kub... no ...
Dans l'exemple ci-dessous nous allons installer le plugin tree
bastion:~$ kubectl krew install tree Updated the local copy of plugin index. Installing plugin: tree Installed plugin: tree \ | Use this plugin: | kubectl tree | Documentation: | https://github.com/ahmetb/kubectl-tree | Caveats: | \ | | * For resources that are not in default namespace, currently you must | | specify -n/--namespace explicitly (the current namespace setting is not | | yet used). | / / WARNING: You installed plugin "tree" from the krew-index plugin repository. These plugins are not audited for security by the Krew maintainers. Run them at your own risk.
Tree est un plugin kubectl pour explorer les relations de propriété entre les objets Kubernetes à travers les ownersReferences.
bastion:~$ kubectl tree deploy hello-kubernetes NAMESPACE NAME READY REASON AGE default Deployment/hello-kubernetes - 38m default └─ReplicaSet/hello-kubernetes-85c7d7db45 - 38m default └─Pod/hello-kubernetes-85c7d7db45-xnkp4 True 38m
Pour maintenir à jour, rien de plus simple en exécutant la commande ci dessous.
bastion:~$ kubectl krew upgrade