在Openshift上安装卷时出错(下一代)

时间:2016-11-15 17:57:12

标签: mongodb docker openshift kubernetes docker-volume

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

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

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控制台的完整日志:

enter image description here

我使用的模板内容是:

{
    "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日志中的挂载问题的更多详细信息?

1 个答案:

答案 0 :(得分:0)

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

  1. 您的模板设置为从Dockerhub上的Mongo图像中提取(由空白“命名空间”值指定。当尝试从Web UI中的Dockerhub中提取mongo:最新图像时,您会看到一条友好的消息通知您docker镜像因为以root身份运行而无法使用: OpenShift error
  2. OpenShift在线开发预览 最近有一些与PVC相关的问题(http://status.preview.openshift.com/)。特别是这个报告的错误,https://bugzilla.redhat.com/show_bug.cgi?id=1392650。这可能是一些问题的原因,因为OpenShift上的“官方”Mongo图像也无法构建。
  3. 我想引导您使用OpenShift MongoDB模板,而不是开发人员预览版中使用的模板,但希望能提供一些好的方向! https://github.com/openshift/openshift-ansible/blob/master/roles/openshift_examples/files/examples/v1.4/db-templates/mongodb-persistent-template.json