Kubernetes Context & Namespace Switcher For PowerShell, Works Like A Charm

Jung Hyun, Nam
DataSeries
Published in
2 min readMar 9, 2020

--

https://unsplash.com/photos/aYHzEnSEH-w

If you are stick with Kubernetes every day, you may know or consider shorthand expression of the kubectl.

I’m using the alias K, kubectx and kubens every day. But these scripts are not designed for PowerShell. So I tried to make the own version of each shorthand convention. Naturally, you can use below snippets to your other environments, including Windows.

Requirements

These modules require the PSFzf module and fzf binary for your operating system.

The “K” Alias

Set-Alias k kubectl

The “Select-KubeContext” (a.k.a. kubectx)

function global:Select-KubeContext {
[CmdletBinding()]
[Alias('kubectx')]
param (
[parameter(Mandatory=$False,Position=0,ValueFromRemainingArguments=$True)]
[Object[]] $Arguments
)
begin {
if ($Arguments.Length -gt 0) {…

--

--

Jung Hyun, Nam
DataSeries

Works at DEVSISTERS, Corp., Microsoft MVP since 2009, Living in S.Korea.