在 kubernetes 中安装 dotnet cor 应用程序时保留新的配置文件

Persist new config files when installing dotnet cor app in kubernetes

我是 Kubernetes 的新手,我正在努力安装应用程序本身,因为新的配置文件没有得到持久化,而不是 pods 的部署。

我第一次 运行 应用程序时,我看到了安装面板,我可以在其中设置基本数据,例如数据库服务器、数据库名称、user/pass 等等。安装完成后,应用程序将重新启动,我会像假设的那样丢失所有信息。

所以我尝试将 /app 添加为 mountPath,但是当我这样做时,我发现 dotnet SDK 未安装并且 pod 从未创建,尽管我认为我不应该保留整个 /app 文件夹,所以我也尝试了 mountPath /app/App_Data,当我这样做时,pod 已启动,但 App_Data 中缺少文件,因此安装无法继续。

这是我正在使用的代码。部署在 DigitalOcean 中完成。

这是我正在使用的 yaml,我需要做什么才能安装应用程序并在重新启动 pod 后获取应用程序新的新配置文件?我是否应该创建一个 docker 已经具备所有必需配置的映像,而不是直接从 pod 安装它?

PVC

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-nopcommerce
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: do-block-storage
  resources:
    requests:
      storage: 5Gi

服务

apiVersion: v1
kind: Service
metadata:
  name: nopcommerce
  labels:
    app: nopcommerce
spec:
  ports:
  - name: nopcommerce
    port: 80
  selector:
    app: nopcommerce

部署

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nopcommerce
spec:
  selector:
    matchLabels:
      app: nopcommerce
  replicas: 1
  template:
    metadata:
      labels:
        app: nopcommerce
    spec:
      containers:
      - name: nopcommerce
        image: nopcommerce/nopcommerce:4.2
        ports:
          - containerPort: 80
        volumeMounts:
        - name: nopcommerce
          mountPath: /app
      volumes:
      - name: nopcommerce
        persistentVolumeClaim:
          claimName: pvc-nopcommerce   

根据您的描述,问题似乎是由于安装卷代替了其他文件,并且由于安装隐藏了这些文件。

你对此无能为力,这就是它的工作原理,这是预期的行为。

如果您需要保留一个目录并且其中仍有一些文件,请考虑在启动应用程序之前将这些文件从其他路径复制到此路径。 您可以使用 initContainers 或入口点脚本来实现它。


Should I create a docker image that already has all needed configuration instead of installing it from the pod directly

这完全取决于具体问题,但通常这是一个好主意。