Skip to content

Instantly share code, notes, and snippets.

@spmason
Created Dec 15, 2021
Embed
What would you like to do?
Command for working with k8s contexts without needing to use kubectx or similar
#!/bin/bash
set -ue -o pipefail
CLUSTER=$1
shift
CLUSTER_KUBECONFIG="$HOME/.kube/config.${CLUSTER}"
if ! [ -f $CLUSTER_KUBECONFIG ]; then
echo "current-context: ${CLUSTER}" > $CLUSTER_KUBECONFIG
fi
export KUBECONFIG=${CLUSTER_KUBECONFIG}:$HOME/.kube/config
exec kubectl $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment