---
# System prepended metadata

title: 2048 遊戲部屬到 k8s
tags: [K8S]

---

# 2048 遊戲部屬到 k8s



```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: "2048-deployment"
spec:
  selector:
    matchLabels:
      app: "2048"
  replicas: 5
  template:
    metadata:
      labels:
        app: "2048"
    spec:
      containers:
        - image: taiwanese/docker-2048
          imagePullPolicy: IfNotPresent
          name: "2048"
          ports:
            - containerPort: 80
              protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: mysvc
  labels:
    app: servicelabel
spec:
  type: NodePort
  ports:
    - port: 80
  selector:
    app: "2048"
```
```
$ kubectl get po,svc
NAME                                   READY   STATUS    RESTARTS   AGE
pod/2048-deployment-7dc8ccd5bb-6qdnn   1/1     Running   0          4m30s
pod/2048-deployment-7dc8ccd5bb-c4q8m   1/1     Running   0          4m30s
pod/2048-deployment-7dc8ccd5bb-dd6dh   1/1     Running   0          4m30s
pod/2048-deployment-7dc8ccd5bb-l9w2x   1/1     Running   0          4m30s
pod/2048-deployment-7dc8ccd5bb-tgr2v   1/1     Running   0          4m30s

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
service/kubernetes   ClusterIP   10.43.0.1      <none>        443/TCP        256d
service/mysvc        NodePort    10.43.189.67   <none>        80:30647/TCP   2m6s
```
* 透過 nodeport 訪問

![image](https://hackmd.io/_uploads/SJ3vt5oR1e.png)

