You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/blog/kubernetes-qol.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,14 @@ image:
19
19
20
20
*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.
21
21
22
+
{{<alerttheme="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
+
{{<alerttheme="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
+
22
30
## `kubectl` auto-complete
23
31
24
32
{{<expand "References">}}
@@ -36,12 +44,12 @@ So, short stories short, and depending on your shell, type in:
36
44
{{<tabs "zsh" "bash">}}
37
45
{{<tab>}}
38
46
```sh
39
-
cat <<EOF | tee -a ~/.zshrc
47
+
cat <<EOF | tee -a {{profileFile}}
40
48
autoload -Uz compinit
41
49
compinit
42
50
source <(kubectl completion zsh)
43
51
EOF
44
-
source~/.zshrc
52
+
source{{profileFile}}
45
53
```
46
54
{{</tab>}}
47
55
{{<tab>}}
@@ -55,11 +63,11 @@ dnf install bash-completion
55
63
source~/.bashrc
56
64
# Check if bash_completion is properly imported, or add it to your bashrc
go get -u github.com/dty1er/kubecolor/cmd/kubecolor
83
+
go install github.com/hidetatz/kubecolor/cmd/kubecolor@latest
76
84
# Make sure kubecolor is found
77
85
which kubecolor
78
86
```
@@ -90,6 +98,9 @@ source ~/.zshrc
90
98
91
99
Finally, you could either use `kubecolor` instead of `kubectl`, or alias `kubectl` as `kubecolor` with the following code sample:
92
100
101
+
102
+
{{<tabs "zsh">}}
103
+
{{<tab>}}
93
104
```sh
94
105
cat <<EOF | tee -a {{profileFile}}
95
106
# Backup original "kubectl" command path. Supports subsequent imports of the file.
@@ -99,10 +110,13 @@ alias kubectll="\${KUBECTL_ORIG_PATH}"
99
110
# Alias kubectl to use colors by default
100
111
alias kubectl="kubecolor"
101
112
# 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
103
115
EOF
104
116
source {{profileFile}}
105
117
```
118
+
{{</tab>}}
119
+
{{</tabs>}}
106
120
107
121
{{<alerttheme="warning">}}
108
122
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
135
149
136
150
To install *krew*, run the following: (taken from [the docs](https://krew.sigs.k8s.io/docs/user-guide/setup/install/))
137
151
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
0 commit comments