如何在kubernetes中在部署时覆盖文件?

如何在kubernetes中在部署时覆盖文件?,kubernetes,push-diffusion,Kubernetes,Push Diffusion,我正在尝试在kubernetes中部署扩散映像,我需要在部署时覆盖一个扩散配置文件 实际上,它是一个系统身份验证。在/opt/Diffusion6.0.3_01/etc/中使用默认凭据存储文件。我正在秘密存储新文件,并将其装入etc/test/,可以在下面的部署文件中看到 template: metadata: labels: run: diffusion spec: serviceAccountName: diffusion-role volumes: - name:

我正在尝试在kubernetes中部署扩散映像,我需要在部署时覆盖一个扩散配置文件

实际上,它是一个
系统身份验证。在
/opt/Diffusion6.0.3_01/etc/
中使用默认凭据存储
文件。我正在秘密存储新文件,并将其装入
etc/test/
,可以在下面的部署文件中看到

template:
metadata:
  labels:
    run: diffusion
spec:
  serviceAccountName: diffusion-role
  volumes:
  - name: diffusion-secrets
    secret:
      secretName: diffusion-license
  - name: ssl-cert
    secret:
      secretName: ssl-certificate
  - name: system-authentication
    secret:
      secretName: system-authentication-store
  containers:
  - image: pushtechnology/diffusion:6.0.3
    imagePullPolicy: IfNotPresent
    name: diffusion
    ports:
    - containerPort: 8080
      protocol: TCP
    - containerPort: 8443
      protocol: TCP
    volumeMounts:
    - name: diffusion-secrets
      mountPath: /etc/diffusion-secrets
      readOnly: true
    - name: ssl-cert
      mountPath: /etc/test/
      readOnly: true
    - name: system-authentication
      mountPath: /etc/test/
    command: [ "/bin/sh", "-c", "cp etc/test/SystemAuthentication.store /opt/DIffusion6.0.3_01" ]
当我部署此映像吊舱时

Events:
Type     Reason                 Age              From                                   Message
----     ------                 ----             ----                               -------
Normal   Scheduled              2m               default-scheduler                  Successfully assigned diffusion-db6d6df7b-f5tp4 to timmy.pushtechnology.com
Normal   SuccessfulMountVolume  2m               kubelet, timmy.pushtechnology.com  MountVolume.SetUp succeeded for volume "diffusion-role-token-n59ds"
Normal   SuccessfulMountVolume  2m               kubelet, timmy.pushtechnology.com  MountVolume.SetUp succeeded for volume "ssl-cert"
Normal   SuccessfulMountVolume  2m               kubelet, timmy.pushtechnology.com  MountVolume.SetUp succeeded for volume "system-authentication"
Normal   SuccessfulMountVolume  2m               kubelet, timmy.pushtechnology.com  MountVolume.SetUp succeeded for volume "diffusion-secrets"
Normal   Killing                1m (x2 over 1m)  kubelet, timmy.pushtechnology.com  Killing container with id docker://diffusion:FailedPostStartHook
Warning  BackOff                1m (x2 over 1m)  kubelet, timmy.pushtechnology.com  Back-off restarting failed container
Normal   Pulled                 1m (x3 over 2m)  kubelet, timmy.pushtechnology.com  Container image "pushtechnology/diffusion:6.0.3" already present on machine
Normal   Created                1m (x3 over 1m)  kubelet, timmy.pushtechnology.com  Created container
Normal   Started                1m (x3 over 1m)  kubelet, timmy.pushtechnology.com  Started container
Warning  FailedPostStartHook    1m (x3 over 1m)  kubelet, timmy.pushtechnology.com  
Warning  FailedSync             1m (x5 over 1m)  kubelet, timmy.pushtechnology.com  Error syncing pod
我也尝试过这里描述的工作:


同样的结果。

您使用
cp etc/test/SystemAuthentication.store/opt/DIffusion6.0.3_01
重写了容器命令,该命令完成后将退出。库伯内特斯认为这是一次失败


您需要将其替换为
cp etc/test/SystemAuthentication.store/opt/DIffusion6.0.3\u 01&&/path/to/original/binary
,其中最后一个命令是图像启动时不覆盖命令的命令。这取决于您的映像。

您使用
cp etc/test/SystemAuthentication.store/opt/DIffusion6.0.3_01
重写了容器命令,该命令完成后将退出。库伯内特斯认为这是一次失败

您需要将其替换为
cp etc/test/SystemAuthentication.store/opt/DIffusion6.0.3\u 01&&/path/to/original/binary
,其中最后一个命令是图像启动时不覆盖命令的命令。这取决于您的映像。

我认为@svenwtl可能是正确的,但是我正在使用的映像的
Dockerfile有一些复杂的构造,我不知道如何在部署文件中使用。
对我有效的修复(经过长时间的尝试/失败循环)是实际使用容器生命周期挂钩:

    volumeMounts:
    - name: diffusion-secrets
      mountPath: /etc/diffusion-secrets
      readOnly: true
    - name: ssl-cert
      mountPath: /etc/test/
      readOnly: true
    - name: system-authentication
      mountPath: /etc/test1/
    lifecycle:
      postStart:
        exec:
          command: [ "/bin/sh", "-c", "cp -f /etc/test1/SystemAuthentication.store /opt/Diffusion6.0.3_01/etc/" ]
我还在不同的文件夹
/etc/test1
中安装了SystemAuthentication,但我不认为这是修复的一部分。

我认为@svenwtl可能是正确的,但我使用的映像的
Dockerfile
有一些复杂的结构,我不知道如何在部署文件中使用。 对我有效的修复(经过长时间的尝试/失败循环)是实际使用容器生命周期挂钩:

    volumeMounts:
    - name: diffusion-secrets
      mountPath: /etc/diffusion-secrets
      readOnly: true
    - name: ssl-cert
      mountPath: /etc/test/
      readOnly: true
    - name: system-authentication
      mountPath: /etc/test1/
    lifecycle:
      postStart:
        exec:
          command: [ "/bin/sh", "-c", "cp -f /etc/test1/SystemAuthentication.store /opt/Diffusion6.0.3_01/etc/" ]

我还在不同的文件夹
/etc/test1
中安装了SystemAuthentication,但我不认为这是修复的一部分。

请注意,postStart是在实际进程启动后执行的。是的,我理解这一点,正如名称所示“post Start”。我不认为以上是最微妙的解决方案,但它在我的情况下工作。我还尝试使用另一个地方建议的
子路径的解决方案,但它只起到了一半的作用。请注意,postStart是在实际进程已经启动之后执行的。是的,我理解这一点,正如名称所示“post Start”。我不认为以上是最微妙的解决方案,但它在我的情况下工作。我还尝试使用另一个地方建议的
子路径
解决方案,但它只起了一半作用。