Skip to content

Instantly share code, notes, and snippets.

@djw4
Last active July 27, 2022 00:03
Show Gist options
  • Save djw4/44c80cb14f8dd9b415f88290f97c4340 to your computer and use it in GitHub Desktop.
Save djw4/44c80cb14f8dd9b415f88290f97c4340 to your computer and use it in GitHub Desktop.
Install the krew plugin for kubectl
#!/usr/bin/env bash
set -eu
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}"
TMP_DIR=$(mktemp -d)
pushd ${TMP_DIR} 1> /dev/null
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz"
tar zxvf "${KREW}.tar.gz"
./"${KREW}" install krew
popd 1> /dev/null
echo -e '\nexport PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' | tee -a $HOME/.bashrc
echo "alias krew=\"kubectl-krew\"" | tee -a $HOME/.bashrc
echo "Logout to refresh the bash profile"
@djw4
Copy link
Author

djw4 commented Jul 26, 2022

Use like this:

$ bash <(curl -fsSL https://gist.githubusercontent.com/djw4/44c80cb14f8dd9b415f88290f97c4340/raw/1c632bea98a4573491ec2ac96d17b59570116450/install-krew.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment