728x90
반응형
namespace란?
namepace 정의
- 클러스터 하나를 여러 개의 논리적인 단위로 나누어서 사용
- 쿠버네티스 클러스터 하나를 여러 팀이나 사용자가 함께 공유
- 용도에 따라 실행해야 하는 앱을 구분할 때 사용
namepace 명령어
namespace 조회
root@master:~# kubectl get namespaces
NAME STATUS AGE
default Active 3d23h
kube-node-lease Active 3d23h
kube-public Active 3d23h
kube-system Active 3d23h
namespace 생성
root@master:~# kubectl create namespace blue
namespace/blue created
root@master:~# kubectl get namespaces
NAME STATUS AGE
blue Active 6s
default Active 3d23h
kube-node-lease Active 3d23h
kube-public Active 3d23h
kube-system Active 3d23h
namespace 삭제
root@master:~# kubectl delete namespaces blue
namespace "blue" deleted
root@master:~# kubectl get namespaces
NAME STATUS AGE
default Active 3d23h
kube-node-lease Active 3d23h
kube-public Active 3d23h
kube-system Active 3d23h
namespace 생성 (yaml)
root@master:~# kubectl create namespace orange --dry-run -o yaml > orange-ns.yaml
W1115 21:46:37.369391 11945 helpers.go:555] --dry-run is deprecated and can be replaced with --dry-run=client.
root@master:~# cat orange-ns.yaml
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: null
name: orange
spec: {}
status: {}
root@master:~# kubectl get namespaces
NAME STATUS AGE
default Active 3d23h
kube-node-lease Active 3d23h
kube-public Active 3d23h
kube-system Active 3d23h
root@master:~# kubectl create -f orange-ns.yaml
namespace/orange created
root@master:~# kubectl get namespaces
NAME STATUS AGE
default Active 3d23h
kube-node-lease Active 3d23h
kube-public Active 3d23h
kube-system Active 3d23h
orange Active 2s
namespace 지정하여 pod 생성
root@master:~# kubectl create -f nginx.yaml -n orange
pod/nginx created
root@master:~# kubectl get pods -n default
No resources found in default namespace.
root@master:~# kubectl get pods -n orange
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 11s
namespace 지정하여 pod 삭제
root@master:~# kubectl delete pod nginx
Error from server (NotFound): pods "nginx" not found
root@master:~# kubectl delete pod nginx -n orange
pod "nginx" deleted
namepace 스위치
config 정보 조회
root@master:~# kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://10.100.0.104:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
현재 context 조회
root@master:~# kubectl config current-context
kubernetes-admin@kubernetes
namespace 포함하여 context 등록
root@master:~# kubectl config set-context blue@kubernetes --cluster=kubernetes --user=kubernetes-admin --namespace=blue
Context "blue@kubernetes" created.
context 변경
root@master:~# kubectl config use-context blue@kubernetes
Switched to context "blue@kubernetes".
root@master:~# kubectl config current-context
blue@kubernetes
pod 생성
namespace 지정을 하지 않아도 변경된 기본 blue namespace에 생성이 됨
root@master:~# kubectl create -f nginx.yaml
pod/nginx created
root@master:~# kubectl get pods -n blue
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 19s
root@master:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 25s
728x90
반응형
'DevOps > Kubernetes' 카테고리의 다른 글
Kubernetes - pod resource 요청 및 제한 (0) | 2021.11.18 |
---|---|
Kubernetes - static Pod (정적 파드) (0) | 2021.11.18 |
Kubernetes - kubectl 명령어 실습 (0) | 2021.11.14 |
Kubernetes PC에 설치해보기 (0) | 2021.11.14 |
kubernetes 아키텍쳐 (0) | 2021.10.21 |