Skip to content

Instantly share code, notes, and snippets.

@danisla
Created October 18, 2017 21:54
Show Gist options
  • Save danisla/02754f03a478402472f305233f74c013 to your computer and use it in GitHub Desktop.
Save danisla/02754f03a478402472f305233f74c013 to your computer and use it in GitHub Desktop.
Kubernetes Bash Helper Functions
function kube-pod() {
kubectl get pods --selector=run=$1 --output=jsonpath={.items..metadata.name}
}
function helm-install-rbac() {
kubectl create serviceaccount tiller --namespace kube-system
kubectl create clusterrolebinding tiller-cluster-rule \
--clusterrole=cluster-admin \
--serviceaccount=kube-system:tiller
helm init --service-account=tiller
helm repo update
}
function install-kubectl() {
K8S_VERSION=${1:-v1.8.1};
ARCH=amd64;
ROOTFS=${HOME};
BIN_DIR=bin;
K8S_URL=${K8S_URL:-https://storage.googleapis.com/kubernetes-release/release};
curl -sfSL ${K8S_URL}/${K8S_VERSION}/bin/linux/${ARCH}/kubectl > ${ROOTFS}/${BIN_DIR}/kubectl;
[[ $? -ne 0 ]] && echo "ERROR: could not download kubectl" && return 1;
chmod +x ${ROOTFS}/${BIN_DIR}/kubectl;
echo "Installed kubectl in ${BIN_DIR}/kubectl"
}
function kube-set-context() {
ctx=$1
echo "INFO: Setting kubectl context to: ${ctx}"
kubectl config set-context $(kubectl config current-context) --namespace=${ctx}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment