Skip to content

Instantly share code, notes, and snippets.

@ticapix
Last active October 29, 2019 16:46
Show Gist options
  • Save ticapix/450a7cf251cd3d0fd24b98d8087a502a to your computer and use it in GitHub Desktop.
Save ticapix/450a7cf251cd3d0fd24b98d8087a502a to your computer and use it in GitHub Desktop.
K8s activate and deasctivate scripts
#!/bin/sh
ls `pwd`/kubeconfig.yml && export KUBECONFIG=`pwd`/kubeconfig.yml
export PATH=`pwd`:$PATH
export HELM_HOME=`pwd`/.helm
which curl > /dev/null 2>&1 || { echo "try apt-get install curl first"; return 1; }
which jq > /dev/null 2>&1 || { echo "try apt-get install jq first"; return 1; }
# KUBECTL
ls kubectl > /dev/null 2>&1 || curl -LOC - https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
echo "kubectl binary ok"
kubectl config view > /dev/null 2>&1 || { echo "wrong KUBECONFIG value"; return 1; }
echo "kubectl ok"
(kubectl get nodes -o json | jq -e '(.items | length > 0)') > /dev/null 2>&1 || { echo "add at least 1 node"; return 1; }
# HELM
export HELM_INSTALL_DIR=`pwd`
export USE_SUDO=false
ls helm > /dev/null 2>&1 || (curl -C - https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash)
chmod +x ./helm
echo "helm binary ok"
kubectl get clusterrolebinding tiller > /dev/null 2>&1 || kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system
EOF
echo "tiller account ok"
helm version > /dev/null 2>&1 || helm init --upgrade --service-account tiller
echo "helm service ok"
helm repo update
kubectl get deploy,pods -n kube-system -l app=helm
ls kubetail > /dev/null 2>&1 || curl -LO https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail
chmod +x ./kubetail
#!/bin/sh
ls `pwd`/kubeconfig.yml && export KUBECONFIG=`pwd`/kubeconfig.yml
export PATH=`pwd`:$PATH
ls kubectl > /dev/null 2>&1 || exit 0
kubectl -n kube-system delete deployment tiller-deploy
kubectl delete clusterrolebinding tiller
kubectl -n kube-system delete serviceaccount tiller
rm helm tiller kubectl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment