brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Mar 08. 2022

 쿠버3탄- 3. mario 게임

<1> 쿠버네티스에 서비스 올리기

<2> 사용하기

<3> 삭제 하기

<4> 출처





<1> 쿠버네티스에 서비스 올리기



1

LB


cat <<EOF | k 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





2

cat <<EOF | kubectl create -f -



cat <<EOF | k 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: NodePort

  externalTrafficPolicy: Local

EOF




3

kw




# 확인

kubectl get deploy,svc mario



k get deploy,svc,pod



NAME                    READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/mario   0/1     1            0           22s


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

service/chat-app       NodePort    10.102.24.192   <none>        8000:30608/TCP   55m

service/kubernetes     ClusterIP   10.96.0.1       <none>        443/TCP          59d

service/mario          NodePort    10.104.133.73   <none>        80:30392/TCP     22s

service/svc-nodeport   NodePort    10.108.250.58   <none>        9000:30645/TCP   55d


NAME                         READY   STATUS              RESTARTS   AGE

pod/mario-79456cfbd9-vrfwd   0/1     ContainerCreating   0          22s




4

# 게임 웹 접속 주소 확인

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"


(admin-k8s:default) root@k8s-m:~# echo -e "GAME URL = http://$GAMENIP:$GAMENPORT"

GAME URL = http://192.168.100.102:30392





<2> 사용하기


http://192.168.100.102:30392


사용키

s

a





<3> 삭제 하기


kubectl delete deploy,svc mario


k delete deploy,svc mario



다른 게임 해보기

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





<4> 출처



1

https://gasidaseo.notion.site/MSA-12-382799b72d5d49a9a15dcafd123c1aa8



2

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


감사합니다.




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