Last active
January 20, 2023 05:28
-
-
Save kairos03/fe7d1494fcd11e11cca280198517a9ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################################### | |
# KUBECTL BASH Initial setting | |
# | |
# Installed features | |
# - kubectl | |
# - kubectl auto complete | |
# - kubectl alias (k) | |
# - kubectl plugin manager (krew) | |
# - kubectl plubins (ns, ctx, konfig) | |
# | |
# How to apply | |
# 1. open your bash shell with sudoers user | |
# 2. copy this gist `raw url` | |
# 3. change `gist-raw-url` and run this command | |
# bash <(curl -sL [gist-raw-url]) | |
# | |
# Happy kubectl~! | |
# | |
#################################################### | |
# install kubectl | |
echo "[Install Kubectl]" | |
cd /tmp | |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | |
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl | |
# kubectl auto-complete | |
sudo apt-get install -y bash-completion | |
echo '# KUBECTL CONFIG' >>~/.bashrc | |
echo 'alias k=kubectl' >>~/.bashrc | |
echo 'source <(kubectl completion bash | sed 's/kubectl/k/g')' >>~/.bashrc | |
source ~/.bashrc | |
# install krew | |
echo "[Install 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/')" && | |
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 | |
) | |
echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.bashrc | |
source ~/.bashrc | |
# install ctx, ns, konfig | |
echo "[Install krew plugins (ctx, ns, konfig)]" | |
kubectl krew install ctx | |
kubectl krew install ns | |
kubectl krew install konfig | |
# add alias | |
echo 'alias "wk=watch kubectl"' >> ~/.bashrc | |
echo "[Done]" | |
echo "\n\nHappy kubectl~!\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment