aws/k8s, eks study
K8s 기본 네임스페이스 변경
gepp
2022. 6. 14. 10:21
- 기본 네임스페이스 변경
현재 컨텍스트 정보 확인
$ kubectl config current-context
docker-desktop
현재 컨텍스트의 정보 확인
$ kubectl config get-contexts docker-desktop
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* docker-desktop docker-desktop docker-desktop
NAMESPACE가 비어있는 경우 기본 네임스페이스는 default
기본 네임스페이스를 kube-system으로 변경
$ kubectl config set-context docker-desktop --namespace=kube-system
Context "docker-desktop" modified.
재확인
$ kubectl config get-contexts $(kubectl config current-context) --namespace=kube-system
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* docker-desktop docker-desktop docker-desktop kube-system
Window
> kubectl config view | findstr namespace
namespace: kube-system
MacOS & Linux
$ kubectl config view | grep namespace
namespace: kube-system
전체 네임스페이스 확인
$ kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
docker compose-909 1/1 Running 0 46m
..
다시 기본 네임스페이스를 default로 변경시
kubectl config set-context contextname --namespace=default
혹은
kubectl config set-context contextname --namespace-""
사용
또는 kubens 라는 툴을 이용하여 간단하게 네임스페이스 변경
#macOS
$ brew install kubectx
#linux
$ wget https://raw.githubusercontent.com/ahmetb/kubectx/master/kubens
$ kubens
default
docker
...
# change default namespace with kubens tool
$ kubens kube-system
Context "docker-desktop" modified.
Active namespace is "kube-system".