๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

kubernetes

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค krew

 

krew ๋ž€

<aside> ๐Ÿ’ก kubectl์„ ๋ณด๋‹ค ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ ๊ด€๋ฆฌ ๋„๊ตฌ

apt, brew์™€ ๋น„์Šทํ•˜๊ฒŒ kubectl ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  ์„ค์น˜ํ•˜๋Š” ๋„๊ตฌ๋กœ, 2023๋…„ 1์›” ๊ธฐ์ค€

210๊ฐœ์˜ kubectl ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ๋ฐฐํฌ

</aside>

์„ค์น˜

git ์„ค์น˜ 
dnf -y install git

krew ์„ค์น˜
(
  set -x; cd "$(mktemp -d)" &&
  OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
  ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\\(arm\\)\\(64\\)\\?.*/\\1\\2/' -e 's/aarch64$/arm64/')" &&
  KREW="krew-${OS}_${ARCH}" &&
  curl -fsSLO "<https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz>" &&
  tar zxvf "${KREW}.tar.gz" &&
  ./"${KREW}" install krew
)

PATH๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. krew ๋ช…๋ น์–ด๋ฅผ ์ž์ฃผ ์‚ฌ์šฉํ•  ๊ฒƒ ๊ฐ™๋‹ค๋ฉด .bashrc ๋“ฑ์˜ ํŒŒ์ผ์— ์ถ”๊ฐ€ํ•œ๋‹ค.
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

์ ์šฉ
source ~/.bashrc

ํ™•์ธ (์„ค์น˜๊ฐ€๋Šฅ ํ”Œ๋Ÿฌ๊ทธ์ธ๋ฆฌ์ŠคํŠธ)
kubectl krew search

ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜

kube-ctx  ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์ปจํ…์ŠคํŠธ ์„ ํƒ
kubectl krew install ctx

kube-ns  ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋„ค์ž„์ŠคํŽ˜์ด์Šค ๊ฒฉ๋ฆฌ
kubectl krew install ns

์‹คํ–‰ 
kubectl <PLUGIN_NAME>
์„ค์น˜ ๋ชฉ๋ก
kubectl krew list
์—…๋ฐ์ดํŠธ
kubectl krew upgrade <PLUGIN_NAME>

kube-ps1 ์ปค๋งจ๋“œ๋ผ์ธ ์„ค์ •

kube-ps1 ์ปค๋ฉ˜๋“œ๋ผ์ธ์—์„œ ํด๋Ÿฌ์Šคํ„ฐ์™€ ๋„ค์ž„์ŠคํŽ˜์ด์Šค ์ด๋ฆ„ ํ™•์ธ

์„ค์น˜
git clone <https://github.com/jonmosco/kube-ps1.git>

๊ถŒํ•œ ์„ค์ •
chmod +x ./ kube-ps1/kube-ps1.sh

์„ค์ •  vi ~/.bashrc ์ถ”๊ฐ€
source $HOME/kube-ps1/kube-ps1.sh
PS1='[\\u@\\h \\W $(kube_ps1)]\\$'
KUBE_PS1_SYMBOL_ENABLE=false

์ ์šฉ
source ~/.bashrc

cli ์ตœ์ ํ™”

์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด
์น˜ํŠธ์‹œํŠธ <https://kubernetes.io/ko/docs/reference/kubectl/cheatsheet/>

bash-completion์„ค์น˜
dnf install -y bash-completion

์˜๊ตฌ ์ ์šฉ
cat <> ~/.bashrc
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
alias k=kubectl
complete -o default -F __start_kubectl k
EOF

kubectl ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด 
cat <> ~/.bashrc
alias ka='kubectl apply -f'
alias kg='kubectl get'
alias kgp='kubectl get pods -o wide'
alias kgd='kubectl get deploy -o wide'
alias kgs='kubectl get service -o wide'
alias kgn='kubectl get nodes -o wide'
alias kge='kubectl get events -w --field-selector type=Warning'
alias kgv='kubectl get pvc -o wide'
alias kgpa='kubectl get pods -o wide -A'
alias kgpw='kubectl get pods -o wide -w'
alias kgpaw='kubectl get pods -o wide -A -w'
alias krn='kubectl run nginx --image=nginx --restart=Never'
alias kch='kubectl create deployment httpd --image=httpd'
alias kcn='kubectl create deployment nginx --image=nginx'
alias krb='kubectl run busybox --image=busybox:1.28 --restart=Never - - sleep 1d'
EOF

์„ค์ • ์ ์šฉ
source ~/.bashrc