如何检查K8s卷是否正确安装?

时间:2020-09-13 15:37:30

标签: kubernetes kubernetes-jobs

我正在测试是否可以使用initContainer从S3装载数据。我的预期和期望是将相同的卷装入到initContainer和Container中。使用InitContainer将来自S3的数据下载到名为/ s3-data的mountPath上,并且由于Container在initContainer之后运行,因此它可以从安装卷的路径中读取数据。

但是,Container并没有显示任何日志,只是说“流已关闭”。 initContainer显示日志,表明已成功从S3下载数据。

我在做什么错?预先感谢。

apiVersion: batch/v1
kind: Job
metadata:
  name: train-job
spec:
  template:
    spec:
      initContainers:
      - name: data-download
        image: <My AWS-CLI Image>
        command: ["/bin/sh", "-c"]
        args:
          - aws s3 cp s3://<Kubeflow Bucket>/kubeflowdata.tar.gz /s3-data
        volumeMounts:
        - mountPath: /s3-data
          name: s3-data
        env:
        - name: AWS_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef: {key: AWS_ACCESS_KEY_ID, name: aws-secret}
        - name: AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef: {key: AWS_SECRET_ACCESS_KEY, name: aws-secret}
      containers:
      - name: check-proper-data-mount
        image: <My Image>
        command: ["/bin/sh", "-c"]
        args:
          - cd /s3-data
          - echo "Just s3-data dir"
          - ls
          - echo "After making a sample file"
          - touch sample.txt
          - ls
        volumeMounts:
        - mountPath: /s3-data
          name: s3-data
      volumes:
      - name: s3-data
        emptyDir: {}
      restartPolicy: OnFailure
  backoffLimit: 6

1 个答案:

答案 0 :(得分:0)

You can try like the below mentioned the argument part
--- 
apiVersion: v1
kind: Pod
metadata: 
  labels: 
    purpose: demonstrate-command
  name: command-demo
spec: 
  containers: 
    - 
      args: 
        - cd /s3-data;
          echo "Just s3-data dir";
          ls;
          echo "After making a sample file";
          touch sample.txt;
          ls;
      command: 
        - /bin/sh
        - -c
      image: "<My Image>"
      name: containername

供参考: How to set multiple commands in one yaml file with Kubernetes?