Skip to content

Instantly share code, notes, and snippets.

@ariary
Last active November 9, 2022 17:40
Show Gist options
  • Save ariary/26dbbdf7e07bcd98863aa9b3a8fa0e6d to your computer and use it in GitHub Desktop.
Save ariary/26dbbdf7e07bcd98863aa9b3a8fa0e6d to your computer and use it in GitHub Desktop.
Kubernetes VM quick setup
#!/usr/bin/env bash
export BLUE='\033[0;34m'
export NC='\033[0m'
echo -e "${BLUE}[*] Install zsh..${NC}"
sudo apt install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
echo -e "${BLUE}[*] Change zsh theme..${NC}"
sed -i '/ZSH_THEME/c\ZSH_THEME="afowler"' ${HOME}/.zshrc
echo 'plugins=( kube-ps1 kubectl)' >> ${HOME}/.zshrc
echo "source $ZSH/oh-my-zsh.sh" >> ${HOME}/.zshrc
echo "export PROMPT='\$(kube_ps1)'\$PROMPT" >> ${HOME}/.zshrc
echo -e "${BLUE}[*] Install kubectl..${NC}"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
echo -e "${BLUE}[*] Install kind..${NC}"
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
echo -e "${BLUE}[*] Install minikube..${NC}"
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
echo -e "${BLUE}[*] Install kubectx and kubens..${NC}"
git clone https://github.com/ahmetb/kubectx /tmp/kubectx
sudo mv /tmp/kubectx/kubectx /usr/local/bin/
sudo mv /tmp/kubectx/kubens /usr/local/bin/
mkdir -p ~/.oh-my-zsh/completions
chmod -R 755 ~/.oh-my-zsh/completions
mv /tmp/kubectx/completion/_kubectx.zsh ~/.oh-my-zsh/completions/
mv /tmp/kubectx/completion/_kubens.zsh ~/.oh-my-zsh/completions/
rm -rf /tmp/kubectx
echo -e "${BLUE}[*] Install krew..${NC}"
(
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\"" >> ${HOME}/.zshrc
echo -e "${BLUE}[*] Install krew plugins: access-matrix, cyclonus, datree, debug-shell, example, get-all, iexec, net-forward, pod-inspect, rbac-lookup, who-can..${NC}"
kubectl krew install access-matrix
kubectl krew install cyclonus
kubectl krew install debug-shell
kubectl krew install datree
kubectl krew install example
kubectl krew install get-all
kubectl krew install iexec
kubectl krew install net-forward
kubectl krew install pod-inspect
kubectl krew install rbac-lookup
kubectl krew install who-can
#echo -e "${BLUE}[*] Install kubeadm (with kubelet)..${NC}"
#sudo apt-get update
#sudo apt-get install -y apt-transport-https ca-certificates curl
#sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
#echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
#sudo apt-get update
#sudo apt-get install -y kubelet kubeadm kubectl
#sudo apt-mark hold kubelet kubeadm kubectl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment