brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Apr 17. 2023

3. nhn클라우드- nks mario, tetris

<1>  mario  배포

<2> 정리

<3> tetris 배포

<4> 정리

<5> quake3 배포

<6> 정리




<1>  mario  배포


1

터미널 모니터링

watch -d 'kubectl get ns,deploy,svc,pods -o wide'



2

kubectl create namespace mario

k ns mario

Context "default" modified.

Active namespace is "mario".



3

curl -s -O https://raw.githubusercontent.com/gasida/PKOS/main/1/mario.yaml

kubectl apply -f mario.yaml


more mario.yaml


cat <<EOF | kubectl create -f -

apiVersion: apps/v1

kind: Deployment

metadata:

  name: mario

  labels:

    app: mario

spec:

  replicas: 1

  selector:

    matchLabels:

      app: mario

  template:

    metadata:

      labels:

        app: mario

    spec:

      containers:

      - name: mario

        image: pengbai/docker-supermario

---

apiVersion: v1

kind: Service

metadata:

   name: mario

spec:

  selector:

    app: mario

  ports:

  - port: 80

    protocol: TCP

    targetPort: 8080

  type: LoadBalancer

EOF








삭제

kubectl delete deploy,svc mario



4

# 확인

kubectl get deploy,svc mario

kubectl exec deploy/mario -- ps axf


# 게임 웹 접속 주소 확인

GAMENIP=$(kubectl get pod -l app=mario -o jsonpath='{.items[0].status.hostIP}')

GAMENPORT=$(kubectl get svc mario -o jsonpath={.spec.ports[0].nodePort})

echo -e "GAME URL = http://$GAMENIP:$GAMENPORT"


(⎈|default:mario) [root@2048game-nhn-web01 ~]# echo -e "GAME URL = http://$GAMENIP:$GAMENPORT"




4






5

게임 시작 s  입력, 점프(s), 쏘기(a)


6

mario pod에서 웹 접속 확인

kubectl exec -it deploy/mario -- ls /usr/local/tomcat/logs


tail로 접속자 확인

kubectl exec -it deploy/mario -- tail /usr/local/tomcat/logs/localhost_access_log.xxxx-xx-xx.txt




7

삭제

kubectl delete deploy,svc mario




<2> 정리


타입을 노드포트 대신 로드밸런서로 변경하면 외부에서 접속이 가능하다.

  type: LoadBalancer






<3> tetris 배포


1

https://hub.docker.com/r/bsord/tetris


2

kubectl create namespace tetris

k ns tetris



3

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



kubectl delete deploy,svc tetris


4

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

---

apiVersion: v1

kind: Service

metadata:

   name: tetris

spec:

  selector:

    app: tetris

  ports:

  - port: 80

    protocol: TCP

    targetPort: 80

  type: NodePort

EOF


5

// 타입을 로드밸런서로 변경하면 외부에서 접속이 된다.

  type: LoadBalancer



# 확인

kubectl get deploy,svc tetris


topas3@cloudshell:~ (loyal-symbol-386014)$ kubectl get deploy,svc tetris

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/tetris   1/1     1            1           63s

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

service/tetris   LoadBalancer   10.52.1.160   34.72.7.209   80:31120/TCP   56s




# 게임 웹 접속 주소 확인

GAMENIP=$(kubectl get pod -l app=tetris -o jsonpath='{.items[0].status.hostIP}')

GAMENPORT=$(kubectl get svc tetris -o jsonpath={.spec.ports[0].nodePort})

echo -e "GAME URL = http://$GAMENIP:$GAMENPORT"

-------------------------------

GAME URL = http://10.0.0.33:30524



6

화살표키, 일시중지(space bar)


7

kubectl delete deploy,svc tetris



8

기타.

카카오 i cloud는 테트리스 로드밸런서가 사설로 나옴



nhn으로 하면 공인으로 나옴,




<4> 정리


타입을 로드밸런서로 변경하면 외부에서 접속이 된다.

type: LoadBalancer




<5> quake3 배포


1

링크

https://hub.docker.com/r/criticalstack/quake


발표 자료

https://www.slideshare.net/openstack_kr/openinfra-days-korea-2018-track-4-provisioning-dedicated-game-server-on-kubernetes-cluster



2

namespace 생성

kubectl create namespace quake3

(⎈|default:default) [root@2048game-nhn-web01 ~]# k ns quake3


(⎈|default:quake3) [root@2048game-nhn-web01 ~]#



3

(선택)

node 서비스


cat <<EOF | kubectl create -f -

apiVersion: apps/v1

kind: Deployment

metadata:

  name: quake

spec:

  selector:

    matchLabels:

      run: quake

  replicas: 1

  template:

    metadata:

      labels:

        run: quake

      annotations:

        prometheus.io/scrape: 'true'

        prometheus.io/port: '8080'

    spec:

      containers:

      - command:

        - q3

        - server

        - --config=/config/config.yaml

        - --content-server=http://127.0.0.1:9090

        - --agree-eula

        image: docker.io/criticalstack/quake:latest

        name: server

        ports:

        - containerPort: 8080

        readinessProbe:

          tcpSocket:

            port: 8080

          initialDelaySeconds: 15

          periodSeconds: 5

        volumeMounts:

        - name: quake3-server-config

          mountPath: /config

        - name: quake3-content

          mountPath: /assets

      - command:

        - q3

        - content

        - --seed-content-url=http://content.quakejs.com

        image: docker.io/criticalstack/quake:latest

        name: content-server

        ports:

        - containerPort: 9090

        volumeMounts:

        - name: quake3-content

          mountPath: /assets

      volumes:

        - name: quake3-server-config

          configMap:

            name: quake3-server-config

        - name: quake3-content

          emptyDir: {}

---

apiVersion: v1

kind: Service

metadata:

  name: quake

spec:

  type: NodePort

  selector:

    run: quake

  ports:

    - port: 8080

      targetPort: 8080

      name: client

    - port: 27960

      targetPort: 27960

      name: server

    - port: 9090

      targetPort: 9090

      name: content

---

apiVersion: v1

kind: ConfigMap

metadata:

  name: quake3-server-config

data:

  config.yaml: |

    fragLimit: 25

    timeLimit: 15m

    bot:

      minPlayers: 3

    game:

      motd: "Welcome to Critical Stack"

      type: FreeForAll

      forceRespawn: false

      inactivity: 10m

      quadFactor: 3

      weaponRespawn: 3

    server:

      hostname: "quakekube"

      maxClients: 12

      password: "changeme"

    commands:

      - addbot sarge 2

    maps:

    - name: q3dm7

      type: FreeForAll

      timeLimit: 10m

    - name: q3dm17

      type: FreeForAll

    - name: q3wctf1

      type: CaptureTheFlag

      captureLimit: 8

    - name: q3tourney2

      type: Tournament

    - name: q3wctf3

      type: CaptureTheFlag

      captureLimit: 8

    - name: ztn3tourney1

      type: Tournament

EOF



타입을 로드밸런서로 변경하면 외부에서 접속이 된다.

type: LoadBalancer


port를 8080에서 80으로 바꾸면 웹으로 접속도 된다.




4

Every 2.0s: kubectl get all


NAME                         READY   STATUS    RESTARTS   AGE

pod/quake-566d6666f5-kqshs   2/2     Running   0          5m12s


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

service/quake   LoadBalancer   10.254.65.19   133.186.203.88   8080:32389/TCP,27960:31021/TCP,9090:30553/TCP   5m12s


NAME                    READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/quake   1/1     1            1           5m12s


NAME                               DESIRED   CURRENT   READY   AGE

replicaset.apps/quake-566d6666f5   1         1         1       5m12s



http://133.186.203.88:8080/






5

kubectl exec deploy/quake -it -- cat /config/config.yaml


# 프로세스 확인 

kubectl exec deploy/quake -it -c server -- ps axf


kubectl exec deploy/quake -it -c content-server -- ps -ef


# 게임파드가 배포된 노드의 IP 확인

QNAME=$(kubectl get pod -l run=quake -o jsonpath='{.items[0].metadata.name}')

QNODE=$(kubectl get pod $QNAME -o jsonpath={.spec.nodeName})

QNODEIP=$(kubectl get node $QNODE -o jsonpath={.status.addresses[0].address})


# 게임 접속하기 위한 NodePort

QPORT=$(kubectl get service quake -o jsonpath='{.spec.ports[0].nodePort}')


# 게임 접속 웹 URL 접속 확인

echo -e "Quake3 Game Web URL = http://$QNODEIP:$QPORT"


(⎈|default:quake3) [root@2048game-nhn-web01 ~]# echo -e "Quake3 Game Web URL = http://$QNODEIP:$QPORT"

Quake3 Game Web URL = http://10.0.0.33:32280



6

화살표키, CTRL키 , ALT키, Space키



7

k delete service quake

k delete deploy quake

k delete configmap quake3-server-config


kubectl delete deploy,svc quake




<6> 정리


1

타입을 로드밸런서로 변경하면 외부에서 접속이 된다.

type: LoadBalancer


2

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

service/quake   LoadBalancer   10.254.65.19   133.186.203.88   8080:32389/TCP,27960:31021/TCP,9090:30553/TCP   5m12s


8080으로 접속 

http://133.186.203.88:8080/



감사합니다.

매거진의 이전글 2. nhn클라우드- nhn NKS 사용
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari