Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

Copy file inside Kubernetes pod from another container

I need to copy a file inside my pod during the time of creation. I don't want to use ConfigMap and Secrets. I am trying to create a volumeMounts and copy the source file using the kubectl cp command—my manifest looks like this.

apiVersion: v1
kind: Pod
metadata:
    name: copy
    labels:
      app: hello
spec:
  containers:
  - name: init-myservice
    image: bitnami/kubectl
    command: ['kubectl','cp','./test.json','init-myservice:./data']
    volumeMounts:
    - name: my-storage
      mountPath: data
  - name: init-myservices
    image: nginx
    volumeMounts:
    - name: my-storage
      mountPath: data
  volumes:
  - name: my-storage
    emptyDir: {}

But I am getting a CrashLoopBackOff error. Any help or suggestion is highly appreciated.

question from:https://stackoverflow.com/questions/65868982/copy-file-inside-kubernetes-pod-from-another-container

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

it's not possible.

let me explain : you need to think of it like two different machine. here your local machine is the one where the file exist and you want to copy it in another machine with cp. but it's not possible. and this is what you are trying to do here. you are trying to copy file from your machine to pod's machine.

here you can do one thing just create your own docker image for init-container. and copy the file you want to store before building the docker image. then you can copy that file in shared volume where you want to store the file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[5] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...