将图像从本地复制到持久卷

Copy image from local to persistence volume

我正在尝试将图像复制到我的持久卷(这就像我希望我的应用程序在用户没有图像时使用它的默认图像,因此它带有应用程序静态文件)

到目前为止我所做的就是创建 deployments.yml 文件:

- 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 这只是文件的一部分(关注我的问题),所以当我 运行 它在我保存任何图像并删除我的网络服务器 pod 并再次重新创建时它工作得很好旧图像仍然存在美好的。 这是 kubectl get pvc

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

但我的问题是我想将我的默认图像复制到卷中,所以我尝试这样做

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

而且总是同样的问题 Error from server (NotFound): pods "wemet-volume" not found

我尝试更改名称并将默认值添加为命名空间,结果始终相同,我做错了什么吗??

您正在尝试直接复制到名为 my-volume 的 pvc。尝试像这样复制到 pods 安装卷:kubectl cp yourfile.png webserver:/usr/src/app/static/profilepics