Copy image from local to persistence volume

6/17/2020

I'm trying to copy an image to my persistence volume ( it's like a default image that i want from my application to use it when a user have no image so it comes with application static files )

So what i've done so far is creating the deployments.yml file like that :

- apiVersion: apps/v1
  kind: Deployment
  metadata:
    annotations:
      kompose.cmd: kompose convert -f docker-compose.yml -o kubemanifests.yaml
      kompose.version: 1.19.0 (f63a961c)
    creationTimestamp: null
    labels:
      io.kompose.service: webserver
    name: webserver
  spec:
    replicas: 1
    strategy: {}
    selector:
      matchLabels:
        io.kompose.service: webserver
    template:
      metadata:
        annotations:
          kompose.cmd: kompose convert -f docker-compose.yml -o kubemanifests.yaml
          kompose.version: 1.19.0 (f63a961c)
        creationTimestamp: null
        labels:
          io.kompose.service: webserver
      spec:
        containers:
        - image: example.com:5000/app
          name: webserver
          ports:
          - containerPort: 80
          - containerPort: 8000
          resources: {}
          volumeMounts:
            - mountPath: /usr/src/app/static
              name: my-volume
        imagePullSecrets:
          - name: privateregcred
        restartPolicy: Always
        volumes:
          - name: my-volume
            persistentVolumeClaim:
              claimName: my-volume
  status: {}
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    creationTimestamp: null
    labels:
      io.kompose.service: my-volume
    name: my-volume
  spec:
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 2Gi
  status: {}

Ofc this is just a part from the file ( that conserne my problem ), so when i run it it worked perfectly when i save any images and delete my webserver pod and recreate again the old images persists fine. and this is the result of kubectl get pvc

NAME           STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
my-volume   Bound    pvc-e76e8f50-8716-44fa-9d34-9d0b70ae9e4e   2Gi        RWO            standard       45m

But my problem is that i want to copy my default image to the volume, so i tried to do

kubectl cp webServer/app/static/profilepics/default.png pvc/my-volume:/profilepics

and always the same problem Error from server (NotFound): pods "wemet-volume" not found

i tried to change the name add default as namespace and always the same result , am i doing somthing wrong??

-- Amor.o
kubectl
kubernetes
kubernetes-pod
minikube
persistent-volumes

1 Answer

6/17/2020

You‘re trying to copy directly to a pvc named my-volume. Try to copy to the pods mounted volume like so: kubectl cp yourfile.png webserver:/usr/src/app/static/profilepics

-- Michael Johann
Source: StackOverflow