Skip to content

Instantly share code, notes, and snippets.

@lcarva
Last active October 31, 2022 20:13
Show Gist options
  • Save lcarva/9c65671f16edffcd7e8929f0aba51ae7 to your computer and use it in GitHub Desktop.
Save lcarva/9c65671f16edffcd7e8929f0aba51ae7 to your computer and use it in GitHub Desktop.
Easily create a new temporary kubeconfig
#!/bin/bash
# Create a new temporary kubeconfig file and display a command to
# configure the current shell to use the new kubeconfig file.
# This is helpful if you interact with multiple OpenShift clusters
# at the same time.
#
# Usage:
# $(kubectl-new-env)
set -euo pipefail
KUBECONFIG=$(mktemp -t kubeconfig.XXXXX)
chmod og-rwx ${KUBECONFIG}
echo "export KUBECONFIG=${KUBECONFIG}"
@lcarva
Copy link
Author

lcarva commented Jul 23, 2021

I have set this up on my system so a new KubeConfig is created whenever I open a new shell which works well for my use case.

  1. Add this script above somewhere in your filesystem
  2. chmod +x <path-to-script>
  3. Add this to your .bashrc: $(<path-to-file-above)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment