Default namespace 설정

김신영·2024년 8월 12일

Kubernetes

목록 보기
2/6
post-thumbnail

master node 1에서 작업을한다.
worker node 2,3 에서도 kubectl 명령이 되도록 하였으니 방법은 동일하다.

  • 현재 기본 네임스페이스 확인
root@master1:~# kubectl get ns
NAME                          STATUS   AGE
cattle-fleet-system           Active   3d21h
cattle-impersonation-system   Active   3d21h
cattle-system                 Active   3d21h
default                       Active   6d19h
kube-node-lease               Active   6d19h
kube-public                   Active   6d19h
kube-system                   Active   6d19h
local                         Active   6d13h
worker2-dev                   Active   5d22h
worker3-test                    Active   5d22h
root@master1:~# kubectl config view --minify | grep namespace:
    namespace: default
root@master1:~#
 
  • 기본 네임스페이스를 변경하는 것은 아래와 같다.
    root@master1:~# kubectl config set-context --current --namespace=worker2-dev
    Context "default" modified.
    root@master1:~# kubectl config view --minify | grep namespace:
    namespace: worker2-dev
    root@master1:~#
  • 매번 변경해 나가면서 작업하기 불편팜으로 .profile에 함수를 정의해서 사용하자
root@master1:~# vi .profile
중략
...
 
# change namespace
kn() {
   case $1 in
         "dev")
               kubectl config set-context --current --namespace=worker2-dev;;
         "test")
               kubectl config set-context --current --namespace=worker3-test;;
         "current")
               kubectl config view --minify | grep namespace;;
         *)
               kubectl config view --minify | grep namespace;;
   esac
}
~
~
~
".profile" 35 lines, 948 characters written
root@master1:~#
root@master1:~# kn
    namespace: worker3-test
root@master1:~# kn dev
Context "default" modified.
root@master1:~# kn
    namespace: worker2-dev
root@master1:~#

주로 사용하는 리눅스 계정에도 동일하게 적용한다.
worker2,3 에도 동일하게 적용한다.

profile
공부합시다.

0개의 댓글