본문 바로가기

리눅스

[kubernetes] 쿠버네티스 워크로드 - 네임스페이스(namespaces)

반응형

워크로드 - 네임스페이스(namespaces)

네임스페이스 확인

kubectl get namespaces
$ kubectl get namespaces
NAME              STATUS   AGE
default           Active   2d1h
ingress-nginx     Active   2d1h
kube-node-lease   Active   2d1h
kube-public       Active   2d1h
kube-system       Active   2d1h
metallb-system    Active   2d1h
kubectl get pods --namespace kube-system
kubectl get all --namespace kube-system

네임스페이스 생성

kubectl create namespace infrateam
$ kubectl create namespace infrateam
namespace/infrateam created

특정 네임스페이스에서 파드 생성

kubectl run myapp --image=nginx --restart=Never -n infrateam
$ kubectl run myapp --image=nginx --restart=Never -n infrateam
pod/myapp created

특정 네임스페이스에 있는 파드 확인

kubectl get pods -n infrateam
$ kubectl get pods -n infrateam
NAME    READY   STATUS    RESTARTS   AGE
myapp   1/1     Running   0          40s

특정 네임스페이스에 있는 파드 삭제

kubectl delete pods myapp -n infrateam
$ kubectl delete pods myapp -n infrateam
pod "myapp" deleted

특정 네임스페이스 삭제

kubectl delete namespaces infrateam
$ kubectl delete namespaces infrateam
namespace "infrateam" deleted

kubens 명령

kubectx, kubens 설치

sudo git clone https://github.com/ahmetb/kubectx /usr/local/kubectx
sudo ln -s /usr/local/kubectx/kubectx /usr/local/bin/kubectx
sudo ln -s /usr/local/kubectx/kubens /usr/local/bin/kubens
kubectl get pods -n infrateam

default 네임스페이스 확인

kubens

kubens kube-system
$ kubens kube-system
Context "kubernetes-admin@cluster.local" modified.
Active namespace is "kube-system".
kubens

 

참고URL

- kubectx + kubens: Power tools for kubectl : https://github.com/ahmetb/kubectx

- [kubernetes] 쿠버네티스 kubectl config 설정 : https://scbyun.com/1346

 

728x90
반응형