brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Mar 02. 2022

107.네이버 쿠버네티스 서비스에 테트리스 7/10

<1> 네이버 쿠버네티스 서비스 클러스터 생성

<2> 쿠버네티스에 명령내릴 리눅스 명령 서버 접속

<3> 테트리스  게임 올리기

<4> 운영 하기

<5> 네이버 클라우드 컨테이너 서비스 알아보기 




<1> 네이버 쿠버네티스 서비스 클러스터 생성


1

생성과 접속 법

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




<2> 쿠버네티스에 명령내릴 리눅스 명령 서버 접속


passwd root

go1!




<3> 테트리스  게임 올리기


1

cat <<EOF | kubectl create -f -

apiVersion: apps/v1

kind: Deployment

metadata:

  name: tetris

  labels:

    app: tetris

spec:

  replicas: 1

  selector:

    matchLabels:

      app: tetris

  template:

    metadata:

      labels:

        app: tetris

    spec:

      containers:

      - name: tetris

        image: bsord/tetris

EOF


kubectl expose deployment tetris --port=80 --type=LoadBalancer




2

# 확인

kubectl get deploy,svc tetris

 kubectl get deploy,svc,pods

kubectl get deploy,svc,pods -o wide



3

kubectl get deploy,svc tetris

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/tetris   1/1     1            1           59s

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

service/tetris   LoadBalancer   198.19.138.41   default-tetris-2245b-9982291-914a3d8e10c7.sgn.lb.naverncp.com   80:30512/TCP   53s



4

웹 브라우저로 접속하여 게임 하기


http://default-tetris-2245b-9982291-914a3d8e10c7.sgn.lb.naverncp.com/




5

방향키

스페이스키 사용




6

 kubectl get deploy,svc,pods


[root@s17f56ff32ee ~]# kubectl get deploy,svc,pods

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/tetris   1/1     1            1           2m20s


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

service/kubernetes   ClusterIP      198.19.128.1    <none>                              443/TCP        8h

service/tetris       LoadBalancer   198.19.138.41   default-tetris-2245b-9982291-914a3d8e10c7.sgn.lb.naverncp.com   80:30512/TCP   2m15s


NAME                          READY   STATUS    RESTARTS   AGE

pod/tetris-78b8bb6fcb-fqkzk   1/1     Running   0          2m20s



7

kubectl get deploy,svc,pods -o wide


[root@s17f56ff32ee ~]# kubectl get deploy,svc,pods -o wide

NAME        READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES         SELECTOR

deployment.apps/tetris   1/1     1            1           3m38s   tetris       bsord/tetris   app=tetris


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

service/kubernetes   ClusterIP      198.19.128.1    <none>        443/TCP        8h      <none>

service/tetris       LoadBalancer   198.19.138.41   default-tetris-2245b-9982291-914a3d8e10c7.sgn.lb.naverncp.com   80:30512/TCP   3m33s   app=tetris


NAME    READY   STATUS    RESTARTS   AGE     IP     NODE    NOMINATED NODE   READINESS GATES

pod/tetris-78b8bb6fcb-fqkzk   1/1     Running   0          3m39s   198.18.0.55   node11-w-1n7   <none>           <none>





<4> 운영 하기


1

kubectl get deploy,svc,pods


[root@s17f56ff32ee ~]# kubectl get deploy,svc,pods

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/tetris   1/1     1            1           8m48s


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

service/kubernetes   ClusterIP      198.19.128.1    <none>                                  443/TCP        8h

service/tetris       LoadBalancer   198.19.138.41   default-tetris-2245b-9982291-914a3d8e10c7.sgn.lb.naverncp.com   80:30512/TCP   8m42s


NAME                          READY   STATUS    RESTARTS   AGE

pod/tetris-78b8bb6fcb-fqkzk   1/1     Running   0          8m47s




2

서버수 조절

10대로 늘려보기 ~


kubectl scale deployment tetris --replicas=10


kubectl get pods

NAME                      READY   STATUS    RESTARTS   AGE

tetris-78b8bb6fcb-2dqcj   1/1     Running   0          25s

tetris-78b8bb6fcb-5297f   1/1     Running   0          25s

tetris-78b8bb6fcb-8nzfl   1/1     Running   0          25s

tetris-78b8bb6fcb-95nvr   1/1     Running   0          25s

tetris-78b8bb6fcb-fqkzk   1/1     Running   0          10m

tetris-78b8bb6fcb-gk978   1/1     Running   0          25s

tetris-78b8bb6fcb-j4mrf   1/1     Running   0          25s

tetris-78b8bb6fcb-lpfsz   1/1     Running   0          25s

tetris-78b8bb6fcb-lxn4h   1/1     Running   0          25s

tetris-78b8bb6fcb-n5xmg   1/1     Running   0          25s



3

접속자 IP 확인?

아래 명령서 실행시킬 웹브라우저로 서비스 접속해본다.

아래처럼 로그가 나온다.

kubectl logs -l app=tetris -f --max-log-requests 10



4

DNS 에서 로드밸런서를 cname으로 연결

원하는 도메인으로 접속 하면 된다.


Global DNS

도메인

bestgame10.com 



http://1.bestgame10.com/




5

250대로 늘려보기


 kubectl scale deployment tetris --replicas=250

중간에 Pending이 생긴다.


kubectl get deploy,svc,pods -o wide

[root@s17f56ff32ee ~]# kubectl get deploy,svc,pods -o wide



pod/tetris-78b8bb6fcb-tj7kr   1/1     Running   0          3m10s   198.18.1.163   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-tnq99   1/1     Running   0          6m14s   198.18.0.28    node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-tpp2d   0/1     Pending   0          2m44s   <none>         <none>         <none>           <none>

pod/tetris-78b8bb6fcb-tt8rg   1/1     Running   0          6m41s   198.18.1.239   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-ttx8d   1/1     Running   0          3m10s   198.18.0.85    node11-w-1n7 




7

2개로 변경하기


kubectl scale deployment tetris --replicas=2

// Pod들이 종료 된다.


[root@s17f56ff32ee ~]# kubectl get deploy,svc,pods -o wide

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELECTOR

deployment.apps/tetris   2/2     2            2           34m   tetris       bsord/tetris   app=tetris

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

service/kubernetes   ClusterIP      198.19.128.1    <none>      443/TCP        8h    <none>

service/tetris       LoadBalancer   198.19.138.41   default-tetris-2245b-9982291-914a3d8e10c7.sgn.lb.naverncp.com   80:30512/TCP   34m   app=tetris

NAME   READY   STATUS     RESTARTS   AGE     IP   NODE    NOMINATED NODE   READINESS GATES

pod/tetris-78b8bb6fcb-2b7hj   1/1     Terminating   0     6m35s   198.18.1.181   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-2fkdf   1/1     Terminating   0          8m25s   198.18.0.41    node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-2grfg   1/1     Terminating   0          5m40s   198.18.1.187   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-2pw5x   1/1     Terminating   0          7m58s   198.18.0.227   node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-2sp8m   1/1     Terminating   0          6m57s   198.18.1.164   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-45fsb   1/1     Terminating   0          9m24s   198.18.1.166   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-45fxg   1/1     Terminating   0          10m     198.18.1.183   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-4f62d   1/1     Terminating   0          5m40s   198.18.1.39    node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-4hgz2   1/1     Terminating   0          5m40s   198.18.1.174   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-4tzxv   1/1     Terminating   0          6m57s   198.18.1.123   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-4wkhl   1/1     Terminating   0          12m     198.18.1.13    node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-4x4kt   1/1     Terminating   0          6m14s   198.18.0.207   node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-4zv8x   1/1     Terminating   0          6m15s   198.18.0.81    node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-54nbf   1/1     Terminating   0          8m44s   198.18.1.54    node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-54xnt   0/1     Terminating   0          5m40s   198.18.1.160   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-5742m   1/1     Terminating   0          6m15s   198.18.0.139   node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-57pqm   1/1     Terminating   0          5m40s   198.18.1.34    node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-5j8pb   1/1     Terminating   0          9m11s   198.18.0.67    node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-5ngmn   1/1     Terminating   0          12m     198.18.1.36    node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-5rswt   1/1     Terminating   0          12m     198.18.0.182   node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-5w22c   1/1     Running       0          12m     198.18.0.18    node11-w-1n7   <none>           <none>

pod/tetris-78b8bb6fcb-5wstv   1/1     Terminating   0          6m35s   198.18.1.229   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-5zdsl   1/1     Terminating   0          5m40s   198.18.1.162   node11-w-1n6   <none>           <none>

pod/tetris-78b8bb6fcb-67wpd   1/1     Terminating   0          5m40s   198.18.1.213   node11-w-1n6   <no




20

삭제

kubectl delete deploy,svc tetris




<5> 네이버 클라우드 컨테이너 서비스 알아보기 


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



감사합니다.

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