Skip to content

Instantly share code, notes, and snippets.

@BorysVrublevskyi
Last active January 13, 2025 14:19
Show Gist options
  • Save BorysVrublevskyi/9c010484d4c6772540884aa084db70c4 to your computer and use it in GitHub Desktop.
Save BorysVrublevskyi/9c010484d4c6772540884aa084db70c4 to your computer and use it in GitHub Desktop.
Script to import all *.yaml Kubernetes configs for Linux and Windows

Export all yaml files from the ~/.kube dir

Linux

Add next line into ~/.bashrc or ~/.zshrc

export KUBECONFIG=$(for YAML in $(find ${HOME}/.kube -name '*.yaml') ; do echo -n ":${YAML}"; done) 

Windows

Run in PowerShell: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Check Test-Path $PROFILE

If False than run New-Item -ItemType File -Path $PROFILE -Force

Or with one liner if (-Not (Test-Path $PROFILE)) {New-Item -ItemType File -Path $PROFILE -Force}

Ctrl+R then notepad $profile

Paste next script:

function importctx {
    $list=Get-ChildItem -Path $HOME\.kube\ -Filter *.yaml -File -Name #-Recurse
    $env:KUBECONFIG="$HOME\.kube\config"
    foreach ($contect in $list) {
        $env:KUBECONFIG=("$env:KUBECONFIG;$HOME\.kube\$contect")
}}
importctx

Now you can run k9s, kubectl, etc.

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