brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Apr 24. 2022

167. GKE에서 네임스페이스 생성(4/6)


<1> 명령 서버 사용

<2> 네임 스페이스 이해

<3> 네임 스페이스 생성




<1> 명령 서버 사용


가상VM 1대를 만든다.


또는


클라우드 쉘 사용

Cloud Shell




<2> 네임 스페이스 이해


네임 스페이스는 분리된 공간이다.

논리적으로 나눈 공간이다.

네임스페이스를 각각 만들고,  해당 네임스페이스에 Pod를 올려보자.


1

gcloud auth list


2

gcloud config list project


topasseoseo1@cloudshell:~ (secret-zer-3001)$ gcloud config list project

[core]

project = secret-zer-3001



3

Default namespaces ?


kubectl get namespace


4개의 네임 스페이스가 보인다.

[topasseoseo1@instance-4 ~]$ kubectl get namespace


NAME                    STATUS   AGE

default                   Active    23h

kube-node-lease    Active    23h

kube-public           Active    23h

kube-system           Active   23h




4

네임 스페이스 쓰는것들 확인 -> 엄청 많다.


kubectl api-resources --namespaced=true


[topasseoseo1@instance-4 ~]$ kubectl api-resources --namespaced=true

NAME                           SHORTNAMES   APIVERSION                             NAMESPACED   KIND

bindings                                    v1                                     true         Binding

configmaps                     cm           v1                                     true         ConfigMap

endpoints                      ep           v1                                     true         Endpoints

events                         ev           v1                                     true         Event

limitranges                    limits       v1                                     true         LimitRange

persistentvolumeclaims         pvc          v1                                     true         PersistentVolumeClaim

pods                           po           v1                                     true         Pod

podtemplates                                v1                                     true         PodTemplate

replicationcontrollers         rc           v1                                     true         ReplicationController

:

:



5

namespace=kube-system 인것 확인


kubectl get services --namespace=kube-system


[topasseoseo1@instance-4 ~]$ kubectl get services --namespace=kube-system

NAME                   TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)         AGE

default-http-backend   NodePort    10.36.11.14   <none>        80:32124/TCP    23h

kube-dns               ClusterIP   10.36.0.10    <none>        53/UDP,53/TCP   23h

metrics-server         ClusterIP   10.36.1.157   <none>        443/TCP         23h





<3> 네임 스페이스 생성



1

프론트 네임스페이스 a와 b를 만든다.


kubectl create namespace front-a

kubectl create namespace front-b



2

네임스페이스가 4개에서 6개로 되었다.


kubectl get namespace

topasvga0802@k8s-command ~]$ kubectl get namespace


NAME              STATUS   AGE

default           Active   46m

front-a           Active   30s

front-b           Active   8s

kube-node-lease   Active   46m

kube-public       Active   46m

kube-system       Active   46m



3

pod 배포 ?

front-a  네임스페이스에 app-server 라는 pod를 만든다.

front-b  네임스페이스에 app-server 라는 pod를 만든다.


kubectl run app-server --image=centos --namespace=front-a -- sleep infinity

kubectl run app-server --image=centos --namespace=front-b -- sleep infinity



4

-A 옵션으로 전체 pod 들을 확인해보자~


kubectl get pods -A


[topasseoseo1@instance-4 ~]$ kubectl get pods -A

NAMESPACE     NAME                                                  READY   STATUS    RESTARTS   AGE

front-a       app-server                                            1/1     Running   0          43s

front-b       app-server                                            1/1     Running   0          42s

kube-system   event-exporter-gke-5479fd58c8-2rv7k                   2/2     Running   0          23h

kube-system   fluentbit-gke-7fp9d                                   2/2     Running   0          23h

kube-system   fluentbit-gke-m2vsh                                   2/2     Running   0          23h

kube-system   fluentbit-gke-sjmzt                                   2/2     Running   0          23h

kube-system   gke-metrics-agent-9f2j4                               1/1     Running   0          23h

kube-system   gke-metrics-agent-k7jq8                               1/1     Running   0          23h

kube-system   gke-metrics-agent-sq7jf                               1/1     Running   0          23h

kube-system   konnectivity-agent-6dfc446797-9429h                   1/1     Running   0          23h

kube-system   konnectivity-agent-6dfc446797-9v2r5                   1/1     Running   0          23h

kube-system   konnectivity-agent-6dfc446797-jc2xz                   1/1     Running   0          23h

kube-system   konnectivity-agent-autoscaler-6849fff748-lngbg        1/1     Running   0          23h

kube-system   kube-dns-697dc8fc8b-46nkm                             4/4     Running   0          23h

kube-system   kube-dns-697dc8fc8b-w7ff4                             4/4     Running   0          23h

kube-system   kube-dns-autoscaler-844c9d9448-5hgpb                  1/1     Running   0          23h

kube-system   kube-proxy-gke-cluster-1-default-pool-f9cbf060-cmtb   1/1     Running   0         23h

kube-system   kube-proxy-gke-cluster-1-default-pool-f9cbf060-gxd8   1/1     Running   0          23h

kube-system   kube-proxy-gke-cluster-1-default-pool-f9cbf060-ql0j   1/1     Running   0          23h

kube-system   l7-default-backend-69fb9fd9f9-gz2xd                   1/1     Running   0          23h

kube-system   metrics-server-v0.4.5-bbb794dcc-w9sqq                 2/2     Running   0          23h

kube-system   pdcsi-node-49c5n                                      2/2     Running   0          23h

kube-system   pdcsi-node-cr27q                                      2/2     Running   0          23h

kube-system   pdcsi-node-plw84                                      2/2     Running   0          23h



5

상세

-namespace 태그로 네임스페이스를 지정해, 새로 생성된  pod에 대한 추가 세부 정보를 본다.


kubectl describe pod app-server --namespace=front-a


6

모든 명령에서  kubectl사용하는 대신, 컨텍스트에서 한 번만 설정 --namespace

이후는  --namespace 지정하지 않고 사용 가능하다.


컨텍스트에 저장해 기본 네임스페이스를 지정한다 ^^

kubectl config set-context --current --namespace=front-a


[topasseoseo1@instance-4 ~]$ kubectl config set-context --current --namespace=front-a

Context "gke_secret-zephyr-348001_asia-northeast3-a_cluster-1" modified.




7

app-server pod를 상세 확인한다.

위에서 컨텍스트에 저장해 기본 네임스페이스를 front-a로 지정했다.

상세 확인

kubectl describe pod app-server



8

app-server pod를  확인한다.


 kubectl get pods


[topasseoseo1@instance-4 ~]$ kubectl get pods

NAME         READY   STATUS    RESTARTS   AGE

app-server   1/1     Running   0          3m9s



9

전체 pod 보기

kubectl get pods -A



10

다음 자료~


https://brunch.co.kr/@topasvga/2381






같이 볼만한 자료


https://brunch.co.kr/@topasvga/1837



https://brunch.co.kr/@topasvga/2383


감사합니다.








매거진의 이전글 166. 콘솔에서 GKE생성(3/6)

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari