k8s实战之dst-admin-go项目
目录
准备工作
从官网找到对应的docker镜像,并明确配置文件。
dst-admin-go镜像安装
docker pull hujinbo23/dst-admin-go:1.2.8
docker run -d -p8082:8082 hujinbo23/dst-admin-go:1.2.8
+ 容器存档启动路径: /root/.klei/DoNotStarveTogether
+ 容器存档备份路径: /app/backup
+ 容器存档模组路径: /app/mod
+ 容器玩家日志路径: /app/dst-db
+ 容器服务日志路径: /app/dst-admin-go.log
+ 容器启动饥荒路径: /app/dst-dedicated-server
+ 容器启steamcmd:/app/steamcmd
配置deployment
对于dst-admin-go的配置而言,最终重要的是路径映射,环境可以
创建命名空间
apiVersion: v1
kind: Namespace
metadata:
name: dst
PV
具体内容可以看上一篇blog,下面是官方的配置
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0003
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /tmp
server: 172.17.0.2
我们修改为我们的配置
apiVersion: v1
kind: PersistentVolume
metadata:
name: dst-app
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/dst/"
PVC
对于持久卷的分配,我们也是同样的按照模板改改
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dst-app-pvc
namespace: dst
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
deployment
有了PVE后,我们就可以开始创建对应的deployment了
apiVersion: apps/v1
kind: Deployment
metadata:
name: dst-deployment
namespace: dst
spec:
selector:
matchLabels:
app: dst
strategy:
type: Recreate
template:
metadata:
labels:
app: dst
spec:
containers:
- image: hujinbo23/dst-admin-go:1.2.8
name: dst-pod
env:
- name: https_proxy
value: http://172.26.41.219:8001
- name: http_proxy
value: http://172.26.41.219:8001
ports:
- containerPort: 8082
- containerPort: 10999
protocol: UDP
volumeMounts:
- name: app
mountPath: /app
- name: app
mountPath: /root/.klei/
volumes:
- name: app
persistentVolumeClaim:
claimName: dst-app-pvc
配置Service
参考官方的配置以及上一节的配置
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app.kubernetes.io/name: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
我们需要映射两个端口,这里有一个完整的端口描述
ports:
- protocol: TCP
tpye: NodePort
port: 80
targetPort: 9376
name: nginx-http
nodePort: 30080 # 只有NodePort类型的时候才使用
得到我们的配置文件,映射是从外网向内网看到的,所以targtPort指的是pod端口
apiVersion: v1
kind: Service
metadata:
name: dst-svc
namespace: dst
spec:
selector:
app: dst
type: ClusterIP
ports:
- protocol: TCP
name: app
port: 8082
targetPort: 8082
apiVersion: v1
kind: Service
metadata:
name: dst-svc-game
namespace: dst
spec:
selector:
app: dst
type: NodePort
ports:
- protocol: UDP
name: master
port: 30999
targetPort: 30999
NodePort: 30999
- protocol: UDP
name: cave
port: 30998
targetPort: 30998
NodePort: 30998
配置traefik
traefik的安装就看上一篇就看,这篇直接就开始编写traefik的路由
编写最常见的IngressRoute路由即可
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: dst-dashboard-route
namespace: dst
spec:
entryPoints:
- web # 与 configmap 中定义的 entrypoint 名字相同
routes:
- match: Host(`dst.libestor.top`) # 域名
kind: Rule
services:
- name: dst-svc # 与svc的name一致
port: 8082 # 与svc的port一致
需要注意的是,UDP使用代理会比较麻烦,建议直接开放30999和30998的UDP端口,然后外部直接连接就可以了,web界面可以走traefik路由。
总结
对所有的配置文件进行总和:
apiVersion: v1
kind: Namespace
metadata:
name: dst
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: dst-app
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/dst/"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dst-app-pvc
namespace: dst
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dst-deployment
namespace: dst
spec:
selector:
matchLabels:
app: dst
strategy:
type: Recreate
template:
metadata:
labels:
app: dst
spec:
containers:
- image: hujinbo23/dst-admin-go:1.2.8
name: dst-pod
env:
- name: https_proxy
value: http://172.26.41.219:8001
- name: http_proxy
value: http://172.26.41.219:8001
ports:
- containerPort: 8082
- containerPort: 10999
protocol: UDP
volumeMounts:
- name: app
mountPath: /app
- name: app
mountPath: /root/.klei/
volumes:
- name: app
persistentVolumeClaim:
claimName: dst-app-pvc
---
apiVersion: v1
kind: Service
metadata:
name: dst-svc
namespace: dst
spec:
selector:
app: dst
type: ClusterIP
ports:
- protocol: TCP
name: app
port: 8082
targetPort: 8082
---
apiVersion: v1
kind: Service
metadata:
name: dst-svc-game
namespace: dst
spec:
selector:
app: dst
type: NodePort
ports:
- protocol: UDP
name: master
port: 30999
targetPort: 30999
nodePort: 30999
- protocol: UDP
name: cave
port: 30998
targetPort: 30998
nodePort: 30998
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: dst-dashboard-route
namespace: dst
spec:
entryPoints:
- web # 与 configmap 中定义的 entrypoint 名字相同
routes:
- match: Host(`dst.libestor.top`) # 域名
kind: Rule
services:
- name: dst-svc # 与svc的name一致
port: 8082 # 与svc的port一致