Kubectl Plugins and Krew: Difference between revisions

From WilliamsNet Wiki
Jump to navigation Jump to search
(Created page with "[https://krew.sigs.k8s.io/ Krew] helps you discover and install kubectl plugins on your machine. There are a lot of kubectl plugins you can install and use to enhance your Ku...")
 
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:


There are a lot of kubectl plugins you can install and use to enhance your Kubernetes experience.
There are a lot of kubectl plugins you can install and use to enhance your Kubernetes experience.
'''Prerequisites:''' A recent copy of the '''git''' command (such as available from the IUS repo) must be installed for krew to operate.


Let’s get started:
Let’s get started:


1. Install and set up Krew on your machine.
1. Install and set up Krew on your machine and add krew's bin directory to your path
 
(
  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
)
 
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"


2. Download the plugin list:
2. Download the plugin list:
Line 25: Line 39:
  kubectl krew uninstall access-matrix
  kubectl krew uninstall access-matrix


This is pretty much all you need to know as a user to use Krew.
This is pretty much all you need to know as a user to use Krew. Interesting plugins already installed and useful include:
 
{| class="wikitable"
|-
! Plugin !! Description !! Documentation/source
|-
| ctx || Switch between contexts in your kubeconfig || https://github.com/ahmetb/kubectx
|-
| ns || Switch between Kubernetes namespaces || https://github.com/ahmetb/kubectx
|-
| get-all || Like `kubectl get all` but _really_ everything || https://github.com/corneliusweig/ketall
|-
| tail || Stream logs from multiple pods and containers || https://github.com/boz/kail
|}


(copied from https://krew.sigs.k8s.io/docs/user-guide/quickstart/)
(copied from https://krew.sigs.k8s.io/docs/user-guide/quickstart/)

Latest revision as of 14:55, 22 October 2021

Krew helps you discover and install kubectl plugins on your machine.

There are a lot of kubectl plugins you can install and use to enhance your Kubernetes experience.

Prerequisites: A recent copy of the git command (such as available from the IUS repo) must be installed for krew to operate.

Let’s get started:

1. Install and set up Krew on your machine and add krew's bin directory to your path

(
 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
)
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

2. Download the plugin list:

kubectl krew update

3. Discover plugins available on Krew:

kubectl krew search
NAME                            DESCRIPTION                                         INSTALLED
access-matrix                   Show an RBAC access matrix for server resources     no
advise-psp                      Suggests PodSecurityPolicies for cluster.           no
auth-proxy                      Authentication proxy to a pod or service            no
[...]

4. Choose a plugin from the list and install it:

kubectl krew install access-matrix

5. Use the installed plugin:

kubectl access-matrix

6. Keep your plugins up-to-date:

kubectl krew upgrade

7. Uninstall a plugin you no longer use:

kubectl krew uninstall access-matrix

This is pretty much all you need to know as a user to use Krew. Interesting plugins already installed and useful include:

Plugin Description Documentation/source
ctx Switch between contexts in your kubeconfig https://github.com/ahmetb/kubectx
ns Switch between Kubernetes namespaces https://github.com/ahmetb/kubectx
get-all Like `kubectl get all` but _really_ everything https://github.com/corneliusweig/ketall
tail Stream logs from multiple pods and containers https://github.com/boz/kail

(copied from https://krew.sigs.k8s.io/docs/user-guide/quickstart/)