Skip to content

Commit 2f43074

Browse files
committed
write: update kubernetes QOL
1 parent 7c30cd0 commit 2f43074

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

content/blog/kubernetes-qol.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ image:
1919

2020
*Kubernetes* is.... Quite a thing, to say the least ! :sweat_smile: Even if their conceptors did a great job at making the *`kubectl` cli* as usable as possible, it can sometimes be a pain to be productive with it, read outputs, or do repetitive tasks. That's why I wrote this small *Quality of life* improvements post: to regroup some install steps you might have missed, give you some useful 3rd party tools or maybe even give you tips a step ahead.
2121

22+
{{<alert theme="info">}}
23+
Code samples are headed with the expected shell. Since I use ZSH, if there is no indication of the shell, you can assume it would work for pretty much any shell.
24+
{{</alert>}}
25+
26+
{{<alert theme="success">}}
27+
Fill out the {{<var "profileFile">}} with your profile file path. Usually, it's `~/.zshrc` for ZSH, and `~/.bashrc` for bash, but feel free to put all this stuff in a separate file you'll include from your main profile.
28+
{{</alert>}}
29+
2230
## `kubectl` auto-complete
2331

2432
{{<expand "References">}}
@@ -36,12 +44,12 @@ So, short stories short, and depending on your shell, type in:
3644
{{<tabs "zsh" "bash">}}
3745
{{<tab>}}
3846
```sh
39-
cat <<EOF | tee -a ~/.zshrc
47+
cat <<EOF | tee -a {{profileFile}}
4048
autoload -Uz compinit
4149
compinit
4250
source <(kubectl completion zsh)
4351
EOF
44-
source ~/.zshrc
52+
source {{profileFile}}
4553
```
4654
{{</tab>}}
4755
{{<tab>}}
@@ -55,11 +63,11 @@ dnf install bash-completion
5563
source ~/.bashrc
5664
# Check if bash_completion is properly imported, or add it to your bashrc
5765
if ! type _init_completion; then
58-
echo 'source /usr/share/bash-completion/bash_completion' >> ~/.bashrc
66+
echo 'source /usr/share/bash-completion/bash_completion' >> {{profileFile}}
5967
fi
6068
# Source the completion script
61-
echo 'source <(kubectl completion bash)' >> ~/.bashrc
62-
source ~/.bashrc
69+
echo 'source <(kubectl completion bash)' >> {{profileFile}}
70+
source {{profileFile}}
6371
```
6472
{{</tab>}}
6573
{{</tabs>}}
@@ -72,7 +80,7 @@ source ~/.bashrc
7280
{{</expand>}}
7381

7482
```sh
75-
go get -u github.com/dty1er/kubecolor/cmd/kubecolor
83+
go install github.com/hidetatz/kubecolor/cmd/kubecolor@latest
7684
# Make sure kubecolor is found
7785
which kubecolor
7886
```
@@ -90,6 +98,9 @@ source ~/.zshrc
9098

9199
Finally, you could either use `kubecolor` instead of `kubectl`, or alias `kubectl` as `kubecolor` with the following code sample:
92100

101+
102+
{{<tabs "zsh">}}
103+
{{<tab>}}
93104
```sh
94105
cat <<EOF | tee -a {{profileFile}}
95106
# Backup original "kubectl" command path. Supports subsequent imports of the file.
@@ -99,10 +110,13 @@ alias kubectll="\${KUBECTL_ORIG_PATH}"
99110
# Alias kubectl to use colors by default
100111
alias kubectl="kubecolor"
101112
# Enable the autocompletion for the alias too (see auto-complete install above)
102-
complete -o default -F __start_kubectl kubecolor
113+
compdef kubecolor=kubectl
114+
compdef kubectll=kubectl
103115
EOF
104116
source {{profileFile}}
105117
```
118+
{{</tab>}}
119+
{{</tabs>}}
106120

107121
{{<alert theme="warning">}}
108122
I noticed some little things does not work well with `kubecolor`. That's why the script above let you use the original `kubectl` command through `kubectll`. For instance, I noticed that some commands prompting user input (so using *stdin*), such as `kubectl login`, don't work.
@@ -135,7 +149,7 @@ curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bas
135149

136150
To install *krew*, run the following: (taken from [the docs](https://krew.sigs.k8s.io/docs/user-guide/setup/install/))
137151

138-
> Think about replacing `{{profileFile}}` with your actual *zsh* or *bash* profile
152+
> Think about replacing {{<var "profileFile">}} with your actual *zsh* or *bash* profile
139153
140154
```sh
141155
# Install krew

0 commit comments

Comments
 (0)