[Retry, k8s] 27. 클러스터 & 메타데이터 API - 네임스페이스

Date:     Updated:

카테고리:

태그:


🔔 네임스페이스


k8s에는 네임스페이스라는 쿠버네티스 클러스터에서 리소스들을 논리적으로 구분하고 관리하는 오브젝트

  • 네임스페이스를 사용하면 다양한 용도나 사용자별로 리소스를 그룹화하고 접근 제어할 수 있는데, 예를 들어 개발, 테스트, 운영 환경에 따라 네임스페이스를 만들 수 있다.

  • 네임스페이스는 YAML 파일이나 커맨드로 생성할 수 있으며, 리소스의 metadata.namespace 필드에 네임스페이스 이름을 명시하면 해당 네임스페이스에 속하게 된다.

  • 네임스페이스를 삭제하면 해당 네임스페이스에 존재하는 모든 리소스도 함께 삭제되므로 주의해야 한다.

  • 쿠버네티스 클러스터에는 기본적으로 default, kube-public, kube-system의 세 가지 네임스페이스가 존재한다.

    종류 개요
    default 네임스페이스를 명시하지 않은 리소스가 속하는 네임스페이스
    kube-system 쿠버네티스 클러스터 구성에 필수적인 컴포넌트들과 설정값이 있는 네임스페이스
    kube-public 모든 사용자가 읽을 수 있는 공개적인 정보가 있는 네임스페이스
    kube-node-lease 쿠버네티스 클러스터에서 각 노드와 연관된 Lease 오브젝트를 가지고 있는 네임스페이스, Lease 오브젝트는 kubelet이 하트비트를 보내서 컨트롤 플레인이 노드 장애를 감지한다.


(1) 네임스페이스 생성

# 매니페스트로 생성
$ cat <<EOF > sample-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: sample-namespace
EOF


# CLI로 직접 네임스페이스를 생성
$ kubectl create namespace sample-namespace


(2) 네임스페이스를 지정한 리소스 획득

# ceph-csi-cephfs 네임스페이스의 모든 오브젝트를 목록
$ kubectl get all -n ceph-csi-cephfs
NAME                                               READY   STATUS    RESTARTS   AGE
pod/ceph-csi-cephfs-nodeplugin-27pcx               3/3     Running   0          4h25m
pod/ceph-csi-cephfs-nodeplugin-xt7mr               3/3     Running   0          4h25m
pod/ceph-csi-cephfs-provisioner-687456b556-66tlw   5/5     Running   0          4h25m
pod/ceph-csi-cephfs-provisioner-687456b556-lxk6x   5/5     Running   0          4h25m
pod/ceph-csi-cephfs-provisioner-687456b556-z6ld8   0/5     Pending   0          4h25m

NAME                                               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/ceph-csi-cephfs-nodeplugin-http-metrics    ClusterIP   10.96.242.246   <none>        8080/TCP   4h25m
service/ceph-csi-cephfs-provisioner-http-metrics   ClusterIP   10.99.179.136   <none>        8080/TCP   4h25m

NAME                                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/ceph-csi-cephfs-nodeplugin   2         2         2       2            2           <none>          4h25m

NAME                                          READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ceph-csi-cephfs-provisioner   2/3     3            2           4h25m

NAME                                                     DESIRED   CURRENT   READY   AGE
replicaset.apps/ceph-csi-cephfs-provisioner-687456b556   3         3         2       4h25m


# 모든 네임스페이스의 모든 오브젝트 목록 - kubectl get all -A
$ kubectl get all --all-namespaces
NAMESPACE         NAME                                               READY   STATUS    RESTARTS        AGE
ceph-csi-cephfs   pod/ceph-csi-cephfs-nodeplugin-27pcx               3/3     Running   0               4h26m
ceph-csi-cephfs   pod/ceph-csi-cephfs-nodeplugin-xt7mr               3/3     Running   0               4h26m
ceph-csi-cephfs   pod/ceph-csi-cephfs-provisioner-687456b556-66tlw   5/5     Running   0               4h26m
ceph-csi-cephfs   pod/ceph-csi-cephfs-provisioner-687456b556-lxk6x   5/5     Running   0               4h26m
ceph-csi-cephfs   pod/ceph-csi-cephfs-provisioner-687456b556-z6ld8   0/5     Pending   0               4h26m
default           pod/sample-readonly-volumemount                    1/1     Running   0               104m
default           pod/sample-statefulset-with-pvc-0                  1/1     Running   0               4h19m
default           pod/sample-statefulset-with-pvc-1                  1/1     Running   0               4h19m
default           pod/sample-subpath                                 3/3     Running   0               82m
kube-system       pod/coredns-787d4945fb-29vhx                       1/1     Running   0               5h18m
kube-system       pod/coredns-787d4945fb-2ds5w                       1/1     Running   0               5h18m
kube-system       pod/etcd-k8s-master                                1/1     Running   0               5h18m
kube-system       pod/kube-apiserver-k8s-master                      1/1     Running   0               5h18m
kube-system       pod/kube-controller-manager-k8s-master             1/1     Running   0               5h18m
kube-system       pod/kube-proxy-5bszd                               1/1     Running   0               5h18m
kube-system       pod/kube-proxy-nv9rn                               1/1     Running   0               5h18m
kube-system       pod/kube-proxy-q7pl6                               1/1     Running   0               5h18m
kube-system       pod/kube-scheduler-k8s-master                      1/1     Running   0               5h18m
kube-system       pod/weave-net-5xmsr                                2/2     Running   1 (5h18m ago)   5h18m
kube-system       pod/weave-net-ll75p                                2/2     Running   0               5h18m
kube-system       pod/weave-net-wk7wl                                2/2     Running   0               5h18m

NAMESPACE         NAME                                               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE
ceph-csi-cephfs   service/ceph-csi-cephfs-nodeplugin-http-metrics    ClusterIP   10.96.242.246   <none>        8080/TCP                 4h26m
ceph-csi-cephfs   service/ceph-csi-cephfs-provisioner-http-metrics   ClusterIP   10.99.179.136   <none>        8080/TCP                 4h26m
default           service/kubernetes                                 ClusterIP   10.96.0.1       <none>        443/TCP                  5h18m
kube-system       service/kube-dns                                   ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP,9153/TCP   5h18m

NAMESPACE         NAME                                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
ceph-csi-cephfs   daemonset.apps/ceph-csi-cephfs-nodeplugin   2         2         2       2            2           <none>                   4h26m
kube-system       daemonset.apps/kube-proxy                   3         3         3       3            3           kubernetes.io/os=linux   5h18m
kube-system       daemonset.apps/weave-net                    3         3         3       3            3           <none>                   5h18m

NAMESPACE         NAME                                          READY   UP-TO-DATE   AVAILABLE   AGE
ceph-csi-cephfs   deployment.apps/ceph-csi-cephfs-provisioner   2/3     3            2           4h26m
kube-system       deployment.apps/coredns                       2/2     2            2           5h18m

NAMESPACE         NAME                                                     DESIRED   CURRENT   READY   AGE
ceph-csi-cephfs   replicaset.apps/ceph-csi-cephfs-provisioner-687456b556   3         3         2       4h26m
kube-system       replicaset.apps/coredns-787d4945fb                       2         2         2       5h18m

NAMESPACE   NAME                                           READY   AGE
default     statefulset.apps/sample-statefulset-with-pvc   2/2     4h19m


(3) 클러스터를 고유하게 식별하는 방법

여러 k8s 클러스터가 존재하는 경우, k8s 정보를 바탕으로 클러스터를 고유하게 식별하는 방법으로 kube-system 네임스페이스의 UID를 사용하는 방법이 있다.

  • kube-system 네임스페이스에는 중요한 시스템 구성 요소가 기동하고 있어 클러스터에서 지우는 일이 거의 없기 때문에 네임스페이스 리소스의 UID를 사용하여 대체할 수 있다.
# kube-system 네임스페이스 UID 확인
$ kubectl get namespaces kube-system -o jsonpath="{.metadata.uid}"
9494acf6-6028-4a92-a802-f74028d3ccf7

KUBERNETES 카테고리 내 다른 글 보러가기

댓글 남기기