【问题标题】:Copy image from local to persistence volume将图像从本地复制到持久卷
【发布时间】:2020-10-07 20:16:38
【问题描述】:

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

所以到目前为止我所做的就是像这样创建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

我试图更改名称添加默认作为命名空间和总是相同的结果,我做错了吗??

【问题讨论】:

    标签: kubernetes kubectl minikube kubernetes-pod persistent-volumes


    【解决方案1】:

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

    【讨论】:

    • 是的,这是正确的答案,Kubectl cp 仅适用于 POD,因此您需要通过连接到 PVC 的 POD 将文件复制到 PVC
    • 是的,这似乎合乎逻辑,所以我的问题在于理解它的工作原理。非常感谢兄弟,你拯救了我的一天:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    相关资源
    最近更新 更多