justxuewei / cloudreve-docker

Source code of Docker image for Cloudreve V3
https://hub.docker.com/r/xavierniu/cloudreve
MIT License
220 stars 51 forks source link

在k8s中启动时的挂载问题及优化建议 #41

Closed staugur closed 3 years ago

staugur commented 3 years ago

Hi,感谢你的镜像。

我在k8s中用它启动了cloudreve服务,但是有点坑,记录下以供参考。

根据Dockerfile定义,构建的cloudreve-main、启动脚本entrypoint.sh及其他volume统一放到了 /cloudreve 目录下,使用docker挂载完全没问题,不过用在k8s中出现了小坑(我是双节点k3s部署)。

挂载最主要的是conf.ini配置文件,在k8s中,定义为ConfigMap,同其他upload、avatar一起挂载,在启动后报错:无法发现entrypoint.sh,因为默认机制,挂载会清空容器目录中所有数据,当然,可以用subPath解决。

所以,有一个修改建议:编译后的二进制cloudreve-main放到 PATH 下,如 /bin/cloudreve-main,并在编译成功后主动赋予可执行权限,移除entrypoint.sh(有点小洁癖,它本身产生了根进程),并且使用CMD设置默认-c参数,这样可以方便设置conf.ini或用默认,且 /cloudreve 是干净的,示例:

ENTRYPOINT ["cloudreve-main"]
CMD ["-c", "/cloudreve/conf.ini"]

ps:顺道贴一个k8s示例

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: cloudreve-config
data:
  conf.ini: |
    [System]
    Mode = master
    Listen = :5212

    [Database]
    Type = mysql
    Host = mysql-ip-hostname
    Port = 3306
    User = root
    Password = 123456
    Name = cloudreve
    TablePrefix = cd_

    [Redis]
    Server = redis:6379
    Password = 123456
    DB = 0
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloudreve-deploy
  labels:
    app: cloudreve
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cloudreve
  template:
    metadata:
      labels:
        app: cloudreve
      annotations:
        port: "5212"
        golang: "1.16"
        cloudreve: "3.3.1"
        github: "xavier-niu/cloudreve-docker"
    spec:
      nodeSelector: # 固定到某个node标签上
        env: prod
      containers:
        - name: cloudreve
          image: docker.io/xavierniu/cloudreve:3.3.1
          command: ["sh","/cloudreve/entrypoint.sh"]
          ports:
            - containerPort: 5212
          volumeMounts:
            - mountPath: /cloudreve/conf.ini
              name: conf
              readOnly: true
              subPath: conf.ini
            - mountPath: /cloudreve/uploads
              name: upload
            - mountPath: /cloudreve/avatar
              name: avatar
            - mountPath: /cloudreve/cloudreve.db
              name: db
              subPath: cloudreve.db
      volumes:
        - name: conf
          configMap:
            name: cloudreve-config
            items:
              - key: conf.ini
                path: conf.ini
        - name: upload
          hostPath:
            path: /data/share/cloudreve/upload
        - name: avatar
          hostPath:
            path: /data/share/cloudreve/avatar
        - name: db
          hostPath:
            path: /data/share/cloudreve/
---
apiVersion: v1
kind: Service
metadata:
  name: cloudreve-svc
  labels:
    app: cloudreve
spec:
  selector:
    app: cloudreve
  ports:
  - name: cloudreve-port
    protocol: TCP
    port: 5212
    targetPort: 5212
justxuewei commented 3 years ago

目前我已经关掉了挂载conf.ini文件(见develop分支),必须要使用entrypoint.sh,所以恐怕你的要求不能实现。不过放到$PATH中这个是可以实现的。此外,权限问题在下个版本中更新。

staugur commented 3 years ago

👍🏻

justxuewei commented 3 years ago

我已经在develop分支更新了,麻烦等待Github Action结束后用unstable的tag重新部署一下。

staugur commented 3 years ago

unstable 启动没问题(用了sqlite,挂载全都是目录了)

justxuewei commented 3 years ago

unstable 启动没问题(用了sqlite,挂载全都是目录了)

所以目前应该都可以正常运行了吧?

staugur commented 3 years ago

Great! 可以关闭这个issue