Skip to content

Instantly share code, notes, and snippets.

@spmason
Created December 15, 2021 10:42
Show Gist options
  • Save spmason/77e0e4b4bda984248f0b61824c90c08f to your computer and use it in GitHub Desktop.
Save spmason/77e0e4b4bda984248f0b61824c90c08f to your computer and use it in GitHub Desktop.
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