티스토리 뷰

클라우드/k8s

K8S 조금 편하게 쓰는 팁 !

꼬마우뇽이(원종운) 2022. 7. 24. 20:49

kubectx

현재 바라보고 있는 K8S Context를 설정하거나, 등록된 K8S Context를 확인할 수 있습니다.

K8s Context는 /.kube/config 에 등록되어있습니다.

 

설치

brew install kubectx

 

메뉴얼

kubectx --help

USAGE:
  kubectx                       : list the contexts
  kubectx <NAME>                : switch to context <NAME>
  kubectx -                     : switch to the previous context
  kubectx -c, --current         : show the current context name
  kubectx <NEW_NAME>=<NAME>     : rename context <NAME> to <NEW_NAME>
  kubectx <NEW_NAME>=.          : rename current-context to <NEW_NAME>
  kubectx -d <NAME> [<NAME...>] : delete context <NAME> ('.' for current-context)
                                  (this command won't delete the user/cluster entry
                                  that is used by the context)
  kubectx -u, --unset           : unset the current context

  kubectx -h,--help             : show this message

 

1. 등록된 K8S Context 확인하기

kubectx

 

현재 바라보고 있는 K8S Context는 노란색으로 표시됩니다.

 

2. K8S Context Switching

# kubectx <k8s context name>
kubectx docker-desktop

 

현재 바라보고 있는 K8S Context를 특정 K8s Context로 Switching 할 수 있습니다.

 

kubens

현재 바라보고 있는 K8S Context 에서 바라보고 있는 namespace를 설정하거나, 존재하는 namespace를 확인할 수 있습니다.

 

설치

brew install kubens

 

메뉴얼

USAGE:
  kubens                    : list the namespaces in the current context
  kubens <NAME>             : change the active namespace of current context
  kubens -                  : switch to the previous namespace in this context
  kubens -c, --current      : show the current namespace
  kubens -h,--help          : show this message

 

1. 존재하는 Namespace 확인하기

kubens

 

kubectl get ns 결과와 동일하며, 기본으로 K8S 리소스 질의에 사용하는 namespace는 노란색으로 표시됩니다.

 

2. Namespace Switching

# kubens <k8s namespace name>
kubens kube-system

 

K8S 리소스 질의에 사용하는 기본 namespace 를 변경합니다.

 

kube-ps1

현재 바라보고 있는 K8S Context와 K8S Namespace를 Prompt 에서 확인할 수 있습니다.

 

Github : https://github.com/jonmosco/kube-ps1

README에 커스터마이징 하는 방법과 On/Off 방법등이 자세하게 나와있습니다.

 

설치

brew install kube-ps1

Make sure kube-ps1 is loaded from your ~/.zshrc and/or ~/.bashrc:
  source "/opt/homebrew/opt/kube-ps1/share/kube-ps1.sh"
  PS1='$(kube_ps1)'$PS1

결과

 

Prompt 창에서 현재 바라보고 있는 K8s Context와 Namespace를 확인할 수 있습니다.

 

fzf

command-line fuzzy finder

 

Github : https://github.com/junegunn/fzf

fzf가 깔려있다면, kubens , kubectx 명령어를 Interactive 하게 사용할 수 있습니다.

 

설치

brew install fzf

 

kubectx + fzf

검색을 통하여 필터링할 수도 있으며, 키보드를 통하여 주어진 결과에 대하여 포커스를 이동할 수도 있습니다. 또한 엔터를 누를 경우 포커스한 context 로 기본 context 를 변경합니다.

 

kubens + fzf

 

검색을 통하여 필터링할 수도 있으며, 키보드를 통하여 주어진 결과에 대하여 포커스를 이동할 수도 있습니다. 또한 엔터를 누를 경우 포커스한 namespace 로 기본 namespace 를 변경합니다.

 

 

kubectl auto completion

Document : Link

 

# .zshrc 하단에 추가

source <(kubectl completion zsh)

p까지만 치고 Tab을 누를 경우 자동 완성 가능한 커맨드들이 보입니다.

 

알면 편한 다른 플러그인 및 스크립트

K9S

Kubectl 기반 CUI 프로그램입니다.

 

Lens

Kubectl 기반 GUI 프로그램입니다.

 

VSCode K8s Extension

VSCode Extension으로 리소스를 빠르게 편집할 수 있고, Export(Command + S)할 수 있으며, 부가적인 기능(Service Port Forward, Debug, ...)을 빠르게 사용할 수 있습니다.

 

 

로그 출력 관련 스크립트

kubectl-neat

kubectltail

'클라우드 > k8s' 카테고리의 다른 글

KNative 그게 뭘까?!  (0) 2022.07.24
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
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
글 보관함