From 9c8367804c94f3196e084d6a21eb000ac437426e Mon Sep 17 00:00:00 2001 From: mtilson Date: Sun, 5 Dec 2021 14:54:13 +0300 Subject: [PATCH 1/4] short alias to set/show namespace usage: $ kn # shows current namespace $ kn default # switch to specified namespace --- content/en/docs/reference/kubectl/cheatsheet.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/en/docs/reference/kubectl/cheatsheet.md b/content/en/docs/reference/kubectl/cheatsheet.md index 5ea50e9ca6..3278c54f40 100644 --- a/content/en/docs/reference/kubectl/cheatsheet.md +++ b/content/en/docs/reference/kubectl/cheatsheet.md @@ -73,6 +73,9 @@ kubectl config set-context gce --user=cluster-admin --namespace=foo \ && kubectl config use-context gce kubectl config unset users.foo # delete user foo + +# short alias to set/show namespace (useful for CKAD/CKA exams) +alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace $1 || kubectl config view --minify | grep namespace ; } ; f' ``` ## Kubectl apply From 1e85065aaa3e6d67f7e45b2cc8b798d110872f82 Mon Sep 17 00:00:00 2001 From: mtilson Date: Sun, 9 Jan 2022 12:47:43 +0300 Subject: [PATCH 2/4] Alias for context --- content/en/docs/reference/kubectl/cheatsheet.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/en/docs/reference/kubectl/cheatsheet.md b/content/en/docs/reference/kubectl/cheatsheet.md index 3278c54f40..20f5077632 100644 --- a/content/en/docs/reference/kubectl/cheatsheet.md +++ b/content/en/docs/reference/kubectl/cheatsheet.md @@ -74,8 +74,9 @@ kubectl config set-context gce --user=cluster-admin --namespace=foo \ kubectl config unset users.foo # delete user foo -# short alias to set/show namespace (useful for CKAD/CKA exams) -alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace $1 || kubectl config view --minify | grep namespace ; } ; f' +# short alias to set/show context/namespace (useful for CKAD/CKA exams) +alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace $1 || kubectl config view --minify | grep namespace | cut -d" " -f6 ; } ; f' +alias kx='f() { [ "$1" ] && kubectl config use-context $1 || kubectl config current-context ; } ; f' ``` ## Kubectl apply From dc9f8bf21fe6e1835b3429a6d9af2705fee6a202 Mon Sep 17 00:00:00 2001 From: mtilson Date: Mon, 7 Feb 2022 00:43:21 +0300 Subject: [PATCH 3/4] Update content/en/docs/reference/kubectl/cheatsheet.md Co-authored-by: Tim Bannister --- content/en/docs/reference/kubectl/cheatsheet.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/en/docs/reference/kubectl/cheatsheet.md b/content/en/docs/reference/kubectl/cheatsheet.md index 20f5077632..8e94b3c1f0 100644 --- a/content/en/docs/reference/kubectl/cheatsheet.md +++ b/content/en/docs/reference/kubectl/cheatsheet.md @@ -74,7 +74,7 @@ kubectl config set-context gce --user=cluster-admin --namespace=foo \ kubectl config unset users.foo # delete user foo -# short alias to set/show context/namespace (useful for CKAD/CKA exams) +# short alias to set/show context/namespace alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace $1 || kubectl config view --minify | grep namespace | cut -d" " -f6 ; } ; f' alias kx='f() { [ "$1" ] && kubectl config use-context $1 || kubectl config current-context ; } ; f' ``` From 071d27ea12521e1dc45f85c252b7bc5f4cc38d19 Mon Sep 17 00:00:00 2001 From: mtilson Date: Mon, 7 Feb 2022 00:56:58 +0300 Subject: [PATCH 4/4] More clarification according to the discussion --- content/en/docs/reference/kubectl/cheatsheet.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/en/docs/reference/kubectl/cheatsheet.md b/content/en/docs/reference/kubectl/cheatsheet.md index 8e94b3c1f0..fc298ef925 100644 --- a/content/en/docs/reference/kubectl/cheatsheet.md +++ b/content/en/docs/reference/kubectl/cheatsheet.md @@ -74,9 +74,9 @@ kubectl config set-context gce --user=cluster-admin --namespace=foo \ kubectl config unset users.foo # delete user foo -# short alias to set/show context/namespace -alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace $1 || kubectl config view --minify | grep namespace | cut -d" " -f6 ; } ; f' +# short alias to set/show context/namespace (only works for bash and bash-compatible shells, current context to be set before using kn to set namespace) alias kx='f() { [ "$1" ] && kubectl config use-context $1 || kubectl config current-context ; } ; f' +alias kn='f() { [ "$1" ] && kubectl config set-context --current --namespace $1 || kubectl config view --minify | grep namespace | cut -d" " -f6 ; } ; f' ``` ## Kubectl apply