brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Mar 08. 2022

 쿠버3탄- 3. mario 게임

<1> 노트북에 쿠버네티스 실습 환경 구축하기

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

<3> 사용하기

<4> 삭제 하기




<1> 노트북에 쿠버네티스 실습 환경 구축하기


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




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



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: NodePort

  externalTrafficPolicy: Local

EOF




또는 

  type: LoadBalancer



# 확인

kubectl get deploy,svc mario



k get deploy,svc,pod


(admin-k8s:default) root@k8s-m:~# 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





# 게임 웹 접속 주소 확인

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




<3> 사용하기


http://192.168.100.102:30392


사용키

s

a



<4> 삭제 하기


kubectl delete deploy,svc mario




<5> 출처


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



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


감사합니다.




매거진의 이전글 쿠버3탄- 2. quake 게임

작품 선택

키워드 선택 0 / 3 0

댓글여부

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