• 기본 네임스페이스 변경

현재 컨텍스트 정보 확인

$ 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".

 

 

'aws > k8s, eks study' 카테고리의 다른 글

Difference between kubectl apply & create  (0) 2022.06.28
K8s command examples  (0) 2022.06.14
CKA 평가 항목  (0) 2022.04.21
K8s basic command  (0) 2022.04.12
brief concept of eks  (0) 2022.04.06

+ Recent posts