【问题标题】:Error mounting volumes on Openshift (Next gen)在 Openshift(下一代)上安装卷时出错
【发布时间】:2023-03-22 23:54:01
【问题描述】:

我正在测试基于 Docker 和 Kubernetes 的新 Openshift 平台。

我从头开始创建了一个新项目,然后当我尝试部署一个简单的 MongoDB 服务(以及一个 python 应用程序)时,我在 Web 控制台的“监控”部分收到以下错误:

Unable to mount volumes for pod "mongodb-1-sfg8t_rob1(e9e53040-ab59-11e6-a64c-0e3d364e19a5)": timeout expired waiting for volumes to attach/mount for pod "mongodb-1-sfg8t"/"rob1". list of unattached/unmounted volumes=[mongodb-data]
Error syncing pod, skipping: timeout expired waiting for volumes to attach/mount for pod "mongodb-1-sfg8t"/"rob1". list of unattached/unmounted volumes=[mongodb-data]

在容器中安装 PVC 似乎有问题,但是 PVC 已正确创建和绑定:

oc get pvc

返回:

NAME           STATUS    VOLUME         CAPACITY   ACCESSMODES   AGE
mongodb-data   Bound     pv-aws-9dged   1Gi        RWO           29m

我已经使用以下命令对其进行了部署:

oc process -f openshift/templates/mongodb.json | oc create -f -

oc deploy mongodb --latest

来自 Web 控制台的完整日志:

我使用的模板内容是:

{
    "kind": "Template",
    "apiVersion": "v1",
    "metadata": {
        "name": "mongo-example",
        "annotations": {
            "openshift.io/display-name": "Mongo example",
            "tags": "quickstart,mongo"
        }
    },
    "labels": {
        "template": "mongo-example"
    },
    "message": "The following service(s) have been created in your project: ${NAME}.",
    "objects": [
        {
            "kind": "PersistentVolumeClaim",
            "apiVersion": "v1",
            "metadata": {
                "name": "${DATABASE_DATA_VOLUME}"
            },
            "spec": {
                "accessModes": [
                    "ReadWriteOnce"
                ],
                "resources": {
                    "requests": {
                        "storage": "${DB_VOLUME_CAPACITY}"
                    }
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "metadata": {
                "name": "${DATABASE_SERVICE_NAME}",
                "annotations": {
                    "description": "Exposes the database server"
                }
            },
            "spec": {
                "ports": [
                    {
                        "name": "mongodb",
                        "port": 27017,
                        "targetPort": 27017
                    }
                ],
                "selector": {
                    "name": "${DATABASE_SERVICE_NAME}"
                }
            }
        },
        {
            "kind": "DeploymentConfig",
            "apiVersion": "v1",
            "metadata": {
                "name": "${DATABASE_SERVICE_NAME}",
                "annotations": {
                    "description": "Defines how to deploy the database"
                }
            },
            "spec": {
                "strategy": {
                    "type": "Recreate"
                },
                "triggers": [
                    {
                        "type": "ImageChange",
                        "imageChangeParams": {
                            "automatic": true,
                            "containerNames": [
                                "mymongodb"
                            ],
                            "from": {
                                "kind": "ImageStreamTag",
                                "namespace": "",
                                "name": "mongo:latest"
                            }
                        }
                    },
                    {
                        "type": "ConfigChange"
                    }
                ],
                "replicas": 1,
                "selector": {
                    "name": "${DATABASE_SERVICE_NAME}"
                },
                "template": {
                    "metadata": {
                        "name": "${DATABASE_SERVICE_NAME}",
                        "labels": {
                            "name": "${DATABASE_SERVICE_NAME}"
                        }
                    },
                    "spec": {
                        "volumes": [
                            {
                                "name": "${DATABASE_DATA_VOLUME}",
                                "persistentVolumeClaim": {
                                    "claimName": "${DATABASE_DATA_VOLUME}"
                                }
                            }
                        ],
                        "containers": [
                            {
                                "name": "mymongodb",
                                "image": "mongo:latest",
                                "ports": [
                                    {
                                        "containerPort": 27017
                                    }
                                ],
                                "env": [
                                    {
                                        "name": "MONGODB_USER",
                                        "value": "${DATABASE_USER}"
                                    },
                                    {
                                        "name": "MONGODB_PASSWORD",
                                        "value": "${DATABASE_PASSWORD}"
                                    },
                                    {
                                        "name": "MONGODB_DATABASE",
                                        "value": "${DATABASE_NAME}"
                                    }
                                ],
                                "volumeMounts": [
                                    {
                                        "name": "${DATABASE_DATA_VOLUME}",
                                        "mountPath": "/data/db"
                                    }
                                ],
                                "readinessProbe": {
                                    "timeoutSeconds": 1,
                                    "initialDelaySeconds": 5,
                                    "exec": {
                                        "command": [ "/bin/bash", "-c", "mongo --eval 'db.getName()'"]
                                    }
                                },
                                "livenessProbe": {
                                    "timeoutSeconds": 1,
                                    "initialDelaySeconds": 30,
                                    "tcpSocket": {
                                        "port": 27017
                                    }
                                },
                                "resources": {
                                    "limits": {
                                        "memory": "${MEMORY_MONGODB_LIMIT}"
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        }
    ],
    "parameters": [
        {
            "name": "NAME",
            "displayName": "Name",
            "description": "The name",
            "required": true,
            "value": "mongo-example"
        },    
        {
            "name": "MEMORY_MONGODB_LIMIT",
            "displayName": "Memory Limit (MONGODB)",
            "required": true,
            "description": "Maximum amount of memory the MONGODB container can use.",
            "value": "512Mi"
        },
        {
            "name": "DB_VOLUME_CAPACITY",
            "displayName": "Volume Capacity",
            "description": "Volume space available for data, e.g. 512Mi, 2Gi",
            "value": "512Mi",
            "required": true
        },
        {
            "name": "DATABASE_DATA_VOLUME",
            "displayName": "Volumne name for DB data",
            "required": true,
            "value": "mongodb-data"
        },
        {
            "name": "DATABASE_SERVICE_NAME",
            "displayName": "Database Service Name",
            "required": true,
            "value": "mongodb"
        },
        {
            "name": "DATABASE_NAME",
            "displayName": "Database Name",
            "required": true,
            "value": "test1"
        },
        {
            "name": "DATABASE_USER",
            "displayName": "Database Username",
            "required": false    
        },
        {
            "name": "DATABASE_PASSWORD",
            "displayName": "Database User Password",
            "required": false    
        }
    ]
}

我的模板有问题吗?是 OpenShift 问题吗?在哪里以及如何在 OpenShift 日志中获取有关挂载问题的更多详细信息?

【问题讨论】:

标签: mongodb docker openshift kubernetes docker-volume


【解决方案1】:

所以,我认为您遇到了 2 个不同的问题。

  1. 您的模板设置为从 Dockerhub 上的 Mongo 映像中提取(由空白的“命名空间”值指定。当尝试在 Web UI 中从 Dockerhub 中提取 mongo:latest 映像时,您会收到一条友好的消息通知您 docker 映像不可用,因为它以 root 身份运行:
  2. OpenShift 在线开发预览版最近遇到了一些与 PVC 相关的问题 (http://status.preview.openshift.com/)。特别是目前报告的这个错误,https://bugzilla.redhat.com/show_bug.cgi?id=1392650。这可能是导致某些问题的原因,因为 OpenShift 上的“官方”Mongo 映像也无法构建。

我想向您介绍一个 OpenShift MongoDB 模板,而不是开发者预览版中使用的确切模板,但希望能提供一些好的方向! https://github.com/openshift/openshift-ansible/blob/master/roles/openshift_examples/files/examples/v1.4/db-templates/mongodb-persistent-template.json

【讨论】:

  • 您好,我已经尝试使用 openshift mongo 映像,结果相同,即使使用您建议的模板,但挂载问题仍然存在。可能与PVC相关的平台问题有关。
  • 是的,抱歉……就像我说的,你遇到了这两个问题。如果没有 PVC 问题,Dockerhub 镜像仍然会失败,因为 OpenShift Online 不允许镜像以 root 身份运行......但正如您所见,即使是“官方”镜像也会失败。请随时订阅 Bugzilla 错误以关注此问题的解决方案!
  • 好的,我将等待您指出的问题#1392650 的解决方案,那里描述了相同的错误消息。但是我不确定原始的mongo图像是否错误,因为默认的mongod服务以用户mongodb运行,​​无论如何,我会在问题修复后再次尝试确认。感谢您的帮助。
猜你喜欢
  • 2015-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多