k8s实战之dst-admin-go项目

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一致
由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,本站及文章作者不为此承担任何责任。

本站拥有对此文章的修改和解释权。如欲转载或传播此文章,必须保证此文章的完整性,包括版权声明等全部内容。未经本站允许,不得任意修改或者增减此文章内容,不得以任何方式将其用于商业目的
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇