1
# 슈퍼 마리오
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
targetPort: 8080
protocol: TCP
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
k edit svc mario
type: LoadBalancer
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
사용키
s
a
kubectl delete deploy,svc mario
k delete deploy,svc mario
다른 게임 해보기
https://brunch.co.kr/@topasvga/3193
1
https://gasidaseo.notion.site/MSA-12-382799b72d5d49a9a15dcafd123c1aa8
2
https://brunch.co.kr/@topasvga/1656
감사합니다.