Skip to content

Instantly share code, notes, and snippets.

@pizycki
Created April 23, 2021 10:03
Show Gist options
  • Save pizycki/a305def914953eed58bae552b832766b to your computer and use it in GitHub Desktop.
Save pizycki/a305def914953eed58bae552b832766b to your computer and use it in GitHub Desktop.
Interactive Kubernetes Context Set
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".
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