관리 메뉴

피터의 개발이야기

[kubernetes] context 변경을 돕는 kubectx 본문

Kubernetes/kube 개발환경

[kubernetes] context 변경을 돕는 kubectx

기록하는 백앤드개발자 2024. 1. 9. 14:32
반응형

 

[kubernetes] 개발환경 목차

ㅁ 들어가며

 쿠버네티스를 관리하면서 로컬(minikube, docker desktop), AWS(개발, 검수, 운영) 다수의 클러스터를 관리할 경우 context를 자주 옮겨야 한다. kubectl의 기능을 이용할 수 있지만, context를 변경 및 관리를 돕는 kubectx가 있어서 그 설치와 사용법을 정리하였다.

kube ConTeXt에서 줄임말 kubectx

 

관련 글
Kubernetes를 위한 최고의 도구는 무엇입니까?

 

 

ㅁ kubectl의 불편한 점

 ㅇ 명령어가 생각보다 깁니다.

 

관련 글 

[kubernetes] kubectl 다중 클러스터 접근하기, context 변경
ㄴ aws eks 증설하고 context 변경 방법을 정리하였다.

 

ㅁ 설치

# 맥용
$ brew install kubectx

 

ㅁ 자동완성기능

mkdir -p ~/.oh-my-zsh/custom/completions
chmod -R 755 ~/.oh-my-zsh/custom/completions
ln -s /opt/kubectx/completion/_kubectx.zsh ~/.oh-my-zsh/custom/completions/_kubectx.zsh
ln -s /opt/kubectx/completion/_kubens.zsh ~/.oh-my-zsh/custom/completions/_kubens.zsh
echo "fpath=($ZSH/custom/completions $fpath)" >> ~/.zshrc

 ㅇ 에러 없이 정상적으로 진행되었다면 설치가 완료되었다.

 

 ㅇ kubectx 이후 탭키를 누르면 minikube가 자동완성된다.

 

ㅁ 사용방법

## 사용법
$ kubectx -h
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 will not delete the user/cluster entry that is used by the context)

  kubectx -u, --unset           : unset the current context

  kubectx -h,--help             : show this message

## context list
$ kubectx
docker-desktop
minikube

## context 변경
$ kubectx docker-desktop
Switched to context "docker-desktop".

## 이전 context
$ kubectx -
Switched to context "minikube".

## context 이름변경
$ kubectx dockkube=docker-desktop
Context "docker-desktop" renamed to "dockkube".

## context 삭제, 클러스터 삭제 아님
$ kubectx -d minikube
Deleting context "minikube"...
warning: this removed your active context, use "kubectl config use-context" to select a different one
deleted context minikube from /Users/peterseo/.kube/config

## context unset, current context 초기화
$ kubectx -u
Unsetting current context.
Property "current-context" unset.

 

 

 

ㅁ minikube context 재생성

 

 

ㅁ 함께 보면 좋은 사이트

 kubectx github

반응형
Comments