部署应用程序时出错:persistentvolumeclaims 已经存在

Error while deploying application: persistentvolumeclaims already exists

我有一个使用 docker-compose 的 docker 应用程序,我想在 openshift-3 中部署该项目,所以我正在使用 kompose。 这是我的 docker-compose 文件:-

version: '3'

services:
  katana-db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: *****
      POSTGRES_USER: *****
  backend:
    depends_on:
      - katana-db
    build:
      context: .
      dockerfile: dockerfile_uwsgi
    image: warrior_deployment_backend
    extra_hosts:
      - "example.com:100.0.0.201"
    volumes:
      - katana-secrets:/secrets
      - katana-static:/warriorframework_py3/static
      - katana-wapps:/warriorframework_py3/katana/wapps
      - katana-wui:/warriorframework_py3/katana/wui
    ports:
      - "4000:4000"
    environment:
      DB_HOST: katana-db
      DB_NAME: warrior
      DB_USER: *****
      DB_PASSWORD: *****
  migration:
    depends_on:
      - backend
    image: warrior_deployment_backend
    entrypoint: ["sh", "-c"]
    command: ["
      python /warriorframework_py3/katana/manage.py collectstatic --noinput;
      python /warriorframework_py3/katana/manage.py makemigrations;
      python /warriorframework_py3/katana/manage.py migrate;
      echo \"from django.contrib.auth import get_user_model; User = get_user_model(); x = User.objects.create_superuser('admin', '', 'warriorframework') if not User.objects.filter(username='admin').exists() else User.objects.get(username='admin'); x.set_password('warriorframework'); x.save()\" | python /warriorframework_py3/katana/manage.py shell;
      "]
    volumes:
      - katana-static:/warriorframework_py3/static
      - katana-wapps:/warriorframework_py3/katana/wapps
      - katana-wui:/warriorframework_py3/katana/wui
    environment:
      DB_HOST: katana-db
      DB_NAME: warrior
      DB_USER: warrior
      DB_PASSWORD: qwerty
  frontend:
    depends_on:
      - backend
    build:
      context: .
      dockerfile: dockerfile_nginx
    image: warrior_deployment_frontend
    volumes:
      - katana-static:/warriorframework_py3/static
      - nginx-secrets:/secrets
    ports:
      - "9443:8443"
    labels:
      kompose.service.expose: "true"

volumes:
  katana-static:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/katana-static
  katana-wapps:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/wapps
  katana-wui:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/wui
  nginx-secrets:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/nginx-secrets
  katana-secrets:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/katana-secrets

当我 运行:

sudo kompose up --provider openshift

错误如下:

FATA Error while deploying application: persistentvolumeclaims "katana-static" already exists

完整控制台日志如下:

INFO Building image 'warrior_deployment_backend' from directory 'warrior_docker_deployment'
INFO Image 'warrior_deployment_backend' from directory 'warrior_docker_deployment' built successfully
INFO Pushing image 'warrior_deployment_backend:latest'
INFO Multiple authentication credentials detected. Will try each configuration.
INFO Attempting authentication credentials 'docker-registry-default.router.default.svc.cluster.local
INFO Successfully pushed image 'warrior_deployment_backend:latest'
INFO Building image 'warrior_deployment_frontend' from directory 'warrior_docker_deployment'
INFO Image 'warrior_deployment_frontend' from directory 'warrior_docker_deployment' built successfully
INFO Pushing image 'warrior_deployment_frontend:latest' to registry 
INFO Multiple authentication credentials detected. Will try each configuration.
INFO Attempting authentication credentials 'docker-registry-default.router.default.svc.cluster.local
INFO Successfully pushed image 'warrior_deployment_frontend:latest' 
INFO We are going to create OpenShift DeploymentConfigs, Services and PersistentVolumeClaims for your Dockerized application.
If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead.

INFO Deploying application in "rak-warrior-ui" namespace
INFO Successfully created Service: backend
INFO Successfully created Service: frontend
INFO Successfully created DeploymentConfig: backend
INFO Successfully created ImageStream: backend
INFO Successfully created PersistentVolumeClaim: katana-secrets of size 100Mi. If your cluster has dynamic storage provisioning, you don't have to do anything. Otherwise you have to create PersistentVolume to make PVC work
INFO Successfully created PersistentVolumeClaim: katana-static of size 100Mi. If your cluster has dynamic storage provisioning, you don't have to do anything. Otherwise you have to create PersistentVolume to make PVC work
INFO Successfully created PersistentVolumeClaim: katana-wapps of size 100Mi. If your cluster has dynamic storage provisioning, you don't have to do anything. Otherwise you have to create PersistentVolume to make PVC work
INFO Successfully created PersistentVolumeClaim: katana-wui of size 100Mi. If your cluster has dynamic storage provisioning, you don't have to do anything. Otherwise you have to create PersistentVolume to make PVC work
INFO Successfully created DeploymentConfig: frontend
INFO Successfully created ImageStream: frontend
INFO Successfully created Route: frontend
FATA Error while deploying application: persistentvolumeclaims "katana-static" already exists

根据我的 observation/analysis,错误可能是由于以下原因造成的:-

kompose 可能错误地解释了共享卷。如果我更清楚地解释这一点,它就像 "katana-static" 是前端、后端和迁移容器使用的共享卷。 kompose 执行以下步骤(这里我只关注共享卷:katana-static)

  1. kompose up 将读取 docker-compose.yml
  2. 现在第一个容器是后端,所以它在卷下找到 katana-static,所以它创建了卷。
  3. 接下来它转到下一个容器并再次找到 katana-static,因此它再次尝试创建
  4. 由于它尝试再次创建共享持久卷 katana-static,它已经存在,因此抛出我们面临的错误。

如果这确实发生了,那么有什么办法可以解决这个问题?或者是什么导致了这个错误?

如果有任何其他论坛可以问这个问题,请提前在评论 section.Thanks 中分享 link。

问题可能与本地卷有关

volumes:
  katana-static:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/katana-static
  katana-wapps:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/wapps
  katana-wui:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/wui
  nginx-secrets:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/nginx-secrets
  katana-secrets:
    driver: local-persist
    driver_opts:
      mountpoint: /data/local-persist/data/warrior/katana-secrets

本地卷在 openshift 中不起作用。我建议您使用 'kompose convert' 命令将 docker-compose 转换为 kubernetes YAML。

然后查看并更新 pvc 和 pv。然后最后一一部署资源