kubectl

개요

쿠버네티스를 관리할 때 사용하는 cli 명령어.
클러스터 운영에 가장 기본이 되는 명령어라 여태 정리도 할 생각을 못하고 있었다.

당장 시간들여 정리하기보다는 여태 알아낸 좋은 활용팁들을 적는데 활용하고자 한다.
관련한 툴 설치에 대한 내용도 넣는다.

같이 쓰면 좋은 툴

yh, yq

# yaml highlighter
wget https://github.com/andreazorzetto/yh/releases/download/v0.4.0/yh-linux-amd64.zip 
	unzip yh-linux-amd64.zip 
sudo mv yh /usr/local/bin/

# json to yaml translator
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 
sudo chmod +x /usr/local/bin/yq

필요한 yaml 양식을 꺼내고 이걸 색깔을 입혀보고 싶다면?
yaml 파일을 출력하는 명령어 뒤에 jq 마냥 파이프라인으로 출력을 yh로 전달하자.

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

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

krew는 kubectl 플러그인을 편하게 관리할 수 있도록 도와주는 플러그인이다.[1]
다른 방식으로도 플러그인을 설치할 순 있지만, 이렇게 중앙 집중식으로 관리하는 것이 아무래도 편리하다.
Pasted image 20250203221959.png
이제 여기에 원하는 플러그인들을 찾아 설치하면 된다.

kubectl krew install ctx ns get-all neat ktop df-pv mtail tree

이런 식으로 말이다.

명령어

자동완성

echo 'source <(kubectl completion bash)' >> /etc/profile
echo 'alias k=kubectl' >> /etc/profile
echo 'complete -F __start_kubectl k' >> /etc/profile
	
# 양식만 꺼내고 싶다면
$do='--dry-run=client -o yaml | yh'

관련 문서

이름 noteType created

참고


  1. https://krew.sigs.k8s.io/ ↩︎