Created
April 23, 2021 10:03
-
-
Save pizycki/a305def914953eed58bae552b832766b to your computer and use it in GitHub Desktop.
Interactive Kubernetes Context Set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS> cluster | |
1: appsplatform-B-prod-aks01-admin | |
2: appsplatform-B-prod-aksvmss-admin | |
3: dweappsplatform-aks01 | |
4: dweappsplatform-aks01-admin | |
5: minikube | |
Which context do you choose?: 5 | |
Switched to context "minikube". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-KubeCluster { | |
$i = 1 | |
$contexts = kubectl config get-contexts --no-headers -o name | |
$contexts ` | |
| ForEach-Object { | |
Write-Output "$(($i++)): $_" | |
} | |
[int]$answer = Read-Host -Prompt "Which context do you choose?" | |
$choosen = $contexts[($answer-1)] # Counting starts from 1 | |
kubectl config use-context $choosen | |
} | |
# Aliases | |
Set-Alias k kubectl | |
Set-Alias cluster Set-KubeCluster |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment