【问题标题】:Save file to Kubernetes pod during deployment在部署期间将文件保存到 Kubernetes pod
【发布时间】:2021-01-04 02:01:25
【问题描述】:

我试图在 Pod 初始化期间将文件添加到 Pod 的磁盘,但没有运气。下面是我用来部署 pod 的部署文件。文件被下载到持久卷,但 pod 没有进入就绪状态。几秒钟后,Pod 失败并重新构建。这又开始了整个过程。

任何帮助将不胜感激。

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: mapserver
spec:
  selector:
    matchLabels:
      app: mapserver
  template:
    metadata:
      labels:
        app: mapserver
    spec:
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: mapserver-pv-claim
      containers:
      - name: maptiles
        image: klokantech/tileserver-gl
        command: ["/bin/sh"]
        args:
        - -c
        - |
           echo "[INFO] Startingcontainer"; if [ $(DOWNLOAD_MBTILES) = "true" ]; then
             echo "[INFO] Download MBTILES_PLANET_URL";
             rm /data/*
             cd /data/
             curl -k -sSL -X GET -u user:ww $(MBTILES_PLANET_URL) -O
             echo "[INFO] Download finished";
           fi;
         env:
         - name: MBTILES_PLANET_URL
           value: 'https://abc-dev/nexus/repository/xyz-raw/2017-07-03_europe_netherlands.mbtiles'
         - name: DOWNLOAD_MBTILES
           value: 'true'
        livenessProbe:
          failureThreshold: 120
          httpGet:
            path: /health
            port: 80
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 30
          successThreshold: 1
          timeoutSeconds: 5
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        readinessProbe:
          failureThreshold: 120
          httpGet:
            path: /health
            port: 80
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 30
          successThreshold: 1
          timeoutSeconds: 5
        resources:
          limits:
            cpu: 300m
            memory: 3Gi
          requests:
            cpu: 100m
            memory: 1Gi
        volumeMounts:
        - mountPath: "/data"
          name: storage

【问题讨论】:

    标签: kubernetes deployment


    【解决方案1】:

    我试图在 Pod 初始化期间将文件添加到 Pod 的磁盘,但没有成功。

    在这种情况下,您可能想改用InitContainers

    从你的清单来看,你的主命令被执行(复制文件然后退出)终止进程中的容器(和伴随的 pod)。部署然后重新启动退出的 pod 并重复循环。如果您改用InitContainers(与您现在对主容器使用相同的定义和相同的PV),您应该使用运行完成的InitContaienrs预填充数据,然后继续在您的普通容器中使用它(应该将不退出的主进程作为其命令/入口点)。

    注意:如果您不想使用InitContainers 或只是作为快速测试,您可以在您的复制语句后附加一个常规的非退出命令,并检查您是否需要使用 tty 启动容器,取决于您的用例和保持容器正常运行的方式。

    【讨论】:

    • 谢谢,使用 initcontainer 解决了我的问题。
    猜你喜欢
    • 2020-07-06
    • 2021-06-18
    • 2020-07-20
    • 2020-07-27
    • 2020-08-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 2019-10-25
    相关资源
    最近更新 更多