Skip to content

Instantly share code, notes, and snippets.

@caruccio
Last active January 14, 2025 13:32
Show Gist options
  • Save caruccio/b9eb86e307ecc293d5b832af8c577605 to your computer and use it in GitHub Desktop.
Save caruccio/b9eb86e307ecc293d5b832af8c577605 to your computer and use it in GitHub Desktop.
Setup basic kubectl bash env
# curl -sLO https://gist.github.com/caruccio/b9eb86e307ecc293d5b832af8c577605/raw/kubectl-setup.sh && bash -i kubectl-setup.sh
mkdir -p ~/bin ~/opt
## PATH
if ! [[ "$PATH" =~ (^|.*:)(~/bin/?|$HOME/bin/?)(:.*|$) ]]; then
echo 'PATH="~/bin:$PATH"' >> ~/.bashrc
export PATH="~/bin:$PATH"
fi
if ! [[ "$PATH" =~ (^|.*:)($HOME/.krew/?)(:.*|$) ]]; then
echo 'PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.bashrc
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
fi
## kubectl
if ! kubectl version --client 2>/dev/null; then
PS3="Select kubectl version to install: "; \
select v in 1.{15..31}; do break; done
if [ -n "$v" ]; then
curl -kL https://dl.k8s.io/release/v${v}.0/bin/linux/amd64/kubectl -o ~/bin/kubectl
chmod +x ~/bin/kubectl
fi
fi
## kubectl-plugins
## https://github.com/caruccio/kubectl-plugins
if [ -d ~/opt/kubectl-plugins ]; then
cd ~/opt/kubectl-plugins
git pull
else
git clone https://github.com/caruccio/kubectl-plugins ~/opt/kubectl-plugins
fi
cp ~/opt/kubectl-plugins/kubectl-* ~/bin/
## kubectx/kubens
## https://github.com/ahmetb/kubectx
if [ -d ~/opt/kubectx ]; then
cd ~/opt/kubectx
git pull
else
git clone https://github.com/ahmetb/kubectx ~/opt/kubectx
fi
ln -fs ~/opt/kubectx/kubectx ~/bin/kubectx
ln -fs ~/opt/kubectx/kubens ~/bin/kubens
## Autokube
## https://github.com/caruccio/autokube
if [ -d ~/opt/autokube ]; then
cd ~/opt/autokube
git pull
else
git clone https://github.com/caruccio/autokube ~/opt/autokube
fi
make -C ~/opt/autokube install-user
## Aliases
if [ "$(type -t l)" != alias ]; then
echo "alias l='ls -la'" >> ~/.bashrc
fi
## KREW
## https://krew.sigs.k8s.io/docs/user-guide/setup/install/
cd ~/bin
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}
./"${KREW}" install krew
rm -vf "${KREW}.tar.gz" ./krew-${OS}_${ARCH}
kubectl krew index add kvaps https://github.com/kvaps/krew-index
kubectl krew update
printf "%s\n" access-matrix deprecations explore get-all kurt kvaps/node-shell lineage modify-secret outdated pexec score sniff tree \
| xargs kubectl krew install
## Helm
if ! helm version &>/dev/null; then
wget https://get.helm.sh/helm-v3.16.2-$OS-$ARCH.tar.gz
tar xzvf helm-v3.16.2-$OS-$ARCH.tar.gz $OS-$ARCH/helm
mv $OS-$ARCH/helm ~/bin/
rm -f helm-v3.16.2-$OS-$ARCH.tar.gz
fi
echo
echo
echo Update your PATH now with:
echo source ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment