일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 캠핑
- kubernetes-ai
- kubernetes
- 피카푸캠핑도봉산
- IT
- 입문용칼
- kube-ai
- mac터널링
- 파드
- 입문나이프
- karpor
- 쿠버네티스
- macos 터널링
- 피카푸글램핑
- GPU
- 오블완
- k8sgpt
- virt-manager
- 도봉산글램핑
- 티스토리챌린지
- kub-ai
- 쿠버네티스보안
- 피카푸클램핑도봉산
- KVM
- 쿠버네티스기초
- POD
- api-key
- k8s
- AI
- 글램핑
- Today
- Total
마구잡
쿠버네티스 클러스터 플러그인 사용하기 본문
Kubectl 그리고 플러그인
쿠버네티스 클러스터를 관리하기 위해 대시보드, 플러그인등 많은 써드파티 오픈소스들이 시장에 나와있다.
오늘 글에서는 클러스터를 관리하는 가장 기본적인 툴인 kubectl의 확장 플러그인에 대해 다뤄볼까 한다.
( 공식 사이트에서 발췌한 내용을 기반으로 작성하였으나, 명확하지 않은 부분은 경험을 토대로 작성하였습니다.
이는 정확한 정보가 아닐 수 있음을 알려드립니다. )
공식 사이트
( 광고 클릭은 큰 힘이 됩니다! )
Krew – kubectl plugin manager
© 2024 The Kubernetes Authors. Krew is a Kubernetes SIG CLI project. Edit Page ·
krew.sigs.k8s.io
Krew란?
쿠버네티스 커맨드툴인 kubectl의 확장을 도와주는 플러그인 매니저
Krew 설치
전제조건: kubectl v1.12 이상이 필요하다.
전제조건: git 설치되어 있어야 한다.
1. 터미널 환경에서 하기 커맨드 실행
(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)
2. PATH 환경 변수에 추가
$HOME/.krew/bin 디렉터리를 환경 변수에 추가한다. • ~/.bashrc 파일에 다음 줄 추가:
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
3. 쉘 리로드 후 확인
kubectl krew 명령으로 설치를 확인한다.
kubectl krew
krew is the kubectl plugin manager.
You can invoke krew through kubectl: "kubectl krew [command]..."
Usage:
kubectl krew [command]
Available Commands:
help Help about any command
index Manage custom plugin indexes
info Show information about an available plugin
install Install kubectl plugins
list List installed kubectl plugins
search Discover kubectl plugins
uninstall Uninstall plugins
update Update the local copy of the plugin index
upgrade Upgrade installed plugins to newer versions
version Show krew version and diagnostics
Flags:
-h, --help help for krew
-v, --v Level number for the log level verbosity
Use "kubectl krew [command] --help" for more information about a command.
쉘을 리로드 할때 꼭 로그아웃/로그인 절차를 밟을 필요는 없다.
exec bash 커맨드 자신이 로그인 한 쉘을 치환 하면 변수값이 로딩된다.
대표 플러그인 사용해보기
kubectl을 좀 더 편하게 사용가능한 대표 플러그인 2개정도를 설치해본다.
1. kube-ctx: 컨텍스트를 쉽게 변경 가능하게 해주는 플러그인
2. kube-ns: 네임스페이스를 쉽게 변경 가능하게 해주는 플러그인
번외 설치: kube-ps1: 현재 상태를 터미널상 보기 편하게 해주는 터미널 플러그인
kube-ctx
1. 터미널 환경에서 플러그인 검색
root@ubuntu-m1:~# kubectl krew search |grep ctx
allctx Run commands on contexts in your kubeconfig no
ctx Switch between contexts in your kubeconfig no
shell-ctx Shell independent context switching no

2. kube-ctx 설치
root@ubuntu-m1:~# kubectl krew install ctx
Updated the local copy of plugin index.
Installing plugin: ctx
Installed plugin: ctx
\
| Use this plugin:
| kubectl ctx
| Documentation:
| https://github.com/ahmetb/kubectx
| Caveats:
| \
| | If fzf is installed on your machine, you can interactively choose
| | between the entries using the arrow keys, or by fuzzy searching
| | as you type.
| | See https://github.com/ahmetb/kubectx for customization and details.
| /
/
WARNING: You installed plugin "ctx" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
3. krew ctx 확인 및 변경
root@ubuntu-m1:~# kubectl ctx
kubernetes-admin-2@kubernetes-2
kubernetes-admin@kubernetes

노란색 마크가 현재 사용중인 config
root@ubuntu-m1:~# kubectl ctx kubernetes-admin-2@kubernetes-2
Switched to context "kubernetes-admin-2@kubernetes-2".
root@ubuntu-m1:~# kubectl get node
NAME STATUS ROLES AGE VERSION
ubuntu-2-m1 Ready control-plane 7d8h v1.31.1
ubuntu-2-w1 Ready <none> 7d7h v1.31.1
ubuntu-2-w2 Ready <none> 7d7h v1.31.1
다른 클러스터의 노드 확인
kube-ns
1. kube-ns 설치
root@ubuntu-m1:~# kubectl krew install ns
Updated the local copy of plugin index.
Installing plugin: ns
Installed plugin: ns
\
| Use this plugin:
| kubectl ns
| Documentation:
| https://github.com/ahmetb/kubectx
| Caveats:
| \
| | If fzf is installed on your machine, you can interactively choose
| | between the entries using the arrow keys, or by fuzzy searching
| | as you type.
| /
/
WARNING: You installed plugin "ns" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
2. kube-ns 확인 및 변경
root@ubuntu-m1:~# kubectl ns
default
kube-node-lease
kube-public
kube-system
root@ubuntu-m1:~# kubectl ns kube-system
Context "kubernetes-admin-2@kubernetes-2" modified.
Active namespace is "kube-system".
root@ubuntu-m1:~# kubectl get po
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-695bcfd99c-rhjzn 1/1 Running 0 7d8h
calico-node-4p452 1/1 Running 0 7d8h
calico-node-7lqls 1/1 Running 1 7d8h
calico-node-8j8mw 1/1 Running 0 7d8h
coredns-7c65d6cfc9-fgnwk 1/1 Running 0 7d8h
coredns-7c65d6cfc9-xxtc9 1/1 Running 0 7d8h
etcd-ubuntu-2-m1 1/1 Running 2 7d8h
kube-apiserver-ubuntu-2-m1 1/1 Running 0 7d8h
kube-controller-manager-ubuntu-2-m1 1/1 Running 1 7d8h
kube-proxy-gf4lk 1/1 Running 1 7d8h
kube-proxy-sspzd 1/1 Running 0 7d8h
kube-proxy-v4swb 1/1 Running 0 7d8h
kube-scheduler-ubuntu-2-m1 1/1 Running 1 7d8h

네임스페이스 옵션을 붙이지 않아도 kube-system의 POD를 조회
kube-ps
1. kube-ps 설치
root@ubuntu-m1:~# git clone https://github.com/jonmosco/kube-ps1.git
Cloning into 'kube-ps1'...
remote: Enumerating objects: 760, done.
remote: Counting objects: 100% (195/195), done.
remote: Compressing objects: 100% (108/108), done.
remote: Total 760 (delta 107), reused 165 (delta 83), pack-reused 565 (from 1)
Receiving objects: 100% (760/760), 7.72 MiB | 13.63 MiB/s, done.
Resolving deltas: 100% (401/401), done.
2. kube-ps1 디렉터리에서 진행
root@ubuntu-m1:~# cd kube-ps1/
root@ubuntu-m1:~/kube-ps1#
root@ubuntu-m1:~/kube-ps1# chmod +x ./kube-ps1.sh
root@ubuntu-m1:~/kube-ps1# cp kube-ps1.sh /usr/bin/
root@ubuntu-m1:~/kube-ps1# vi ~/.bashrc
... 가장 하단에 삽입
source /usr/bin/kube-ps1.sh
PS1='[\u@\h \W $(kube_ps1)]\$ '
root@ubuntu-m1:~/kube-ps1# exec bash
[root@ubuntu-m1 kube-ps1 (⎈|kubernetes-admin-2@kubernetes-2:kube-system)]#

현재 context와 네임스페이스를 특별한 조회 없이 터미널 환경에서 확인 할 수 있다.
마무리
위처럼 3가지 플러그인을 사용하여 보다 나은 커맨드 환경 제공이 가능하며
현재 Context와 네임스페이스를 가시적으로 확인하여 휴면 에러를 줄일수 있는 환경을 구성할 수 있다.
잘못된 정보나, 문의등은 댓글로 메일과 함께 적어주시면 감사하겠습니다.
'Kubernetes > 작은팁-짧은글' 카테고리의 다른 글
Open-WebUi Ollama API Key 발급방법 (0) | 2025.03.13 |
---|---|
Podman permission denied 문제 (0) | 2025.03.04 |
Kubernetes POD 통신 테스트 ( ping 명령어 없을시 ) (3) | 2024.11.07 |
Kubernetes Ephemeral Storage (1) | 2024.11.04 |
Kubernetes 다중 클러스터 context 추가 및 에러 발생 시나리오 (1) | 2024.10.25 |