Home > Blockchain >  Kubernetes: Cannot VolumeMount emptydir within init container
Kubernetes: Cannot VolumeMount emptydir within init container

Time:10-27

I am trying to make use of amazon/aws-cli docker image for downloading all files from s3 bucket through initcontainer and mount the same volume to the main container.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: test-deployment
  name: test-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-deployment
  template:
    metadata:
      labels:
        app: test-deployment
    spec:
      securityContext:
        fsGroup: 2000
      serviceAccountName: "s3-sa" #Name of the SA we ‘re using
      automountServiceAccountToken: true
      initContainers:
      - name: data-extension
        image: amazon/aws-cli
        volumeMounts:
          - name: data
            mountPath: /data
        command:
          - aws s3 sync s3://some-bucket/ /data
      containers:
      - image: amazon/aws-cli
        name: aws
        command: ["sleep","10000"]
        volumeMounts:
          - name: data
            mountPath: "/data"
      volumes:
        - name: data
          emptyDir: {}

But it does not seems working. It is causing init container to crashbackloop. error:

Error: failed to start container "data-extension": Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "aws s3 sync s3://some-bucket/ /data": stat aws s3 sync s3://some-bucket/ /data: no such file or directory: unknown

CodePudding user response:

Your command needs update:

...
command:
- "aws"
- "s3"
- "sync"
- "s3://some-bucket/"
- "/data"
...
  • Related