Crewe is a kubectl
A command line tool for discovering, managing and installing kubectl plugins. It works like yum, brew and apt. Krew supports more than 100 kubectl plugins.
For developers, you can use Krew to package and distribute plugins on different platforms and make them available to users through a centralized repository.
In this article, we will introduce how to install and use Krew to install the kubectl plugin for a Kubernetes cluster. But first you need to install a running Kubernetes cluster and install kubectl.
Krew can work across platforms such as Windows, Linux and Mac, and supports kubectl v1.12 and higher. We will introduce the installation on Linux, Mac and Windows.
Installation of crew
In this section, we discuss the installation steps of krew on Linux, macOS and Windows systems.
Install Krew on Linux/Mac
- Install Git
## Mac
$ brew install git
##
Debian
/
Ubuntu
$ sudo apt install git-all
## RHEL/
CentOS
$ sudo dnf install git-all
2. Install Krew using the following command on the terminal:
(
set -x; cd "$(mktemp -d)" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" &&
tar zxvf krew.tar.gz &&
KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_$(uname -m | sed -e 's/x86_64/amd64/' -e 's/arm.*$/arm/')" &&
"$KREW" install krew
)
3. After successful installation, you will see output similar to the following example:
......
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%.krewbin 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/.
| /
/
4. Including $HOME/ .krew/bin
Use the following command to access your PATH environment:
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
Install Krew on Windows
- Install Git
- Download git from Here And install.
2. Download and install krew.exe Here To the catalog
3. Start cmd as an administrator and navigate to the directory you downloaded script
4. Install krew using the following command:
krew install krew
5. Including %USERPROFILE%.krewbin
Directory to PATH
Environment variables using this method link
How to use crew
Now that we have Krew installed, let’s explore how to use it.
Here are some commands we will use to start using Krew.
- To download the list of Krew plugins, you can compare it with updating the repo cache using apt or yum:
$ kubectl krew update
2. Discover available Krew plugins:
$ kubectl krew search
NAME DESCRIPTION INSTALLED
access-matrix Show an RBAC access matrix for server resources yes
advise-psp Suggests PodSecurityPolicies for cluster. no
allctx Run commands on contexts in your kubeconfig no
apparmor-manager Manage AppArmor profiles for cluster. no
auth-proxy Authentication proxy to a pod or service no
bd-xray Run Black Duck Image Scans 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
config-cleanup Automatically clean up your kubeconfig no
config-registry Switch between registered kubeconfigs no
creyaml Generate custom resource YAML manifest no
......
3. Install the plugin from Krew
$ kubectl krew install pod-logs
Updated the local copy of plugin index.
Installing plugin: pod-logs
Installed plugin: pod-logs
| Use this plugin:
| kubectl pod-logs
| Documentation:
| https://github.com/danisla/kubefunc
/
WARNING: You installed plugin "pod-logs" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
4. Use the plugin you have installed – you can now execute the plugin using kubectl
$ kubectl pod-logs
1) nginx-ingress-1605802027-controller-ch6ct default Running
2) dashboard-metrics-scraper-79c5968bdc-6p4fv kubernetes-dashboard Running
3) kubernetes-dashboard-665f4c5ff-bgrm2 kubernetes-dashboard Running
4) faas-idler-674fd4544c-tz72x openfaas Running
5) gateway-689746ff97-jqrst openfaas Running
6) nats-cdc589ff7-z8zf2 openfaas Running
Select a Pod: 1
I1119 16:09:26.542094 6 flags.go:205] Watching for Ingress class: nginx
-------------------------------------------------------------------------------
NGINX Ingress controller
Release: v0.34.1
Build: v20200715-ingress-nginx-2.11.0-8-gda5fa45e2
Repository: https://github.com/kubernetes/ingress-nginx
nginx version: nginx/1.19.1
-------------------------------------------------------------------------------
W1119 16:09:26.544149 6 flags.go:250] SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)
W1119 16:09:26.544237 6 client_config.go:552] Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.
I1119 16:09:26.544553 6 main.go:231] Creating API client for https://10.96.0.1:443
I1119 16:09:26.554426 6 main.go:275] Running in Kubernetes cluster version v1.19 (v1.19.4) - git (clean) commit d360454c9bcd1634cf4cc52d1867af5491dc9c5f - platform linux/amd64
I1119 16:09:26.609756 6 main.go:87] Validated default/nginx-ingress-1605802027-default-backend as the default backend.
....
5. To update the plugin, use the following command:
[email protected]:~# kubectl krew upgrade
Updated the local copy of plugin index.
Upgrading plugin: access-matrix
Skipping plugin access-matrix, it is already on the newest version
Upgrading plugin: krew
Skipping plugin krew, it is already on the newest version
Upgrading plugin: ns
Skipping plugin ns, it is already on the newest version
Upgrading plugin: pod-logs
Skipping plugin pod-logs, it is already on the newest version
6. List installed plugins
$ kubectl krew list
PLUGIN VERSION
access-matrix v0.4.5
krew v0.4.0
ns v0.9.1
pod-logs v1.0.1
7. To remove the plugin using Krew, do the following:
$ kubectl krew remove pod-logs
Uninstalled plugin pod-logs
in conclusion
Krew is very convenient for using kubectl to manage kubernetes clusters. This makes it easy to get packaged plugins in a centralized location.
Feel free to try to set it up on your cluster as it also has very simple steps.
Find the following links related to this article
How to install K3s cluster on Ubuntu
Use kubeadm to install a Kubernetes cluster on Ubuntu
Force removal of eviction/terminated Pods in Kubernetes