0

我正在测试基于 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 日志中获取有关挂载问题的更多详细信息?

4

1 回答 1

0

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

  1. 您的模板设置为从 Dockerhub 上的 Mongo 图像中提取(由空白的“命名空间”值指定。当尝试在 Web UI 中从 Dockerhub 中提取 mongo:latest 图像时,您会收到一条友好消息,通知您docker 映像不可用,因为它以 root 身份运行: OpenShift 错误
  2. OpenShift Online Dev preview最近出现了一些与 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

于 2016-11-16T20:44:48.377 回答