3.6. Deploying the database application


Deploy a MongoDB database application to contain the information that your application requires. For this tutorial, you will deploy a database application called mongodb-nationalparks that holds the national park location information.

Prerequisites

  • You have deployed the parksmap front-end application.
  • You have deployed the nationalparks back-end application.

Procedure

  • Deploy the mongodb-nationalparks database application by running the following command:

    $ oc new-app registry.redhat.io/rhmap47/mongodb --name mongodb-nationalparks -e MONGODB_USER=mongodb -e MONGODB_PASSWORD=mongodb -e MONGODB_DATABASE=mongodb -e MONGODB_ADMIN_PASSWORD=mongodb -l 'app.kubernetes.io/part-of=national-parks-app,app.kubernetes.io/name=mongodb'

    Example output

    --> Found container image 7a61087 (12 days old) from quay.io for "quay.io/mongodb/mongodb-enterprise-server"
    
        * An image stream tag will be created as "mongodb-nationalparks:latest" that will track this image
    
    --> Creating resources with label app.kubernetes.io/name=mongodb,app.kubernetes.io/part-of=national-parks-app ...
        imagestream.image.openshift.io "mongodb-nationalparks" created
        deployment.apps "mongodb-nationalparks" created
        service "mongodb-nationalparks" created
    --> Success
        Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
         'oc expose service/mongodb-nationalparks'
        Run 'oc status' to view your app.

Create a Secret resource to securely provide the back-end application with the sensitive database connection credentials.

The nationalparks application needs information, such as the database name, username, and passwords, to access the MongoDB database. However, because this information is sensitive, you should not store it directly in the pod.

You can use a secret to store sensitive information, and share that secret with workloads.

Secret objects provide a mechanism to hold sensitive information such as passwords, OpenShift Container Platform client configuration files, and private source repository credentials. Secrets decouple sensitive content from the pods. You can mount secrets into containers by using a volume plugin or by passing the secret in as an environment variable. The system can then use secrets to provide the pod with the sensitive information.

The following procedure creates the nationalparks-mongodb-parameters secret and mounts it to the nationalparks workload.

Prerequisites

  • You have deployed the nationalparks back-end application.
  • You have deployed the mongodb-nationalparks database application.

Procedure

  1. Create the secret with the required database access information by running the following command:

    $ oc create secret generic nationalparks-mongodb-parameters --from-literal=DATABASE_SERVICE_NAME=mongodb-nationalparks --from-literal=MONGODB_USER=mongodb --from-literal=MONGODB_PASSWORD=mongodb --from-literal=MONGODB_DATABASE=mongodb --from-literal=MONGODB_ADMIN_PASSWORD=mongodb
  2. Import the environment from the secret to the nationalparks workload by running the following command:

    $ oc set env --from=secret/nationalparks-mongodb-parameters deploy/nationalparks
  3. Wait for the nationalparks deployment to roll out a new revision with this environment information. Check the status of the nationalparks deployment by running the following command:

    $ oc rollout status deployment nationalparks

    Example output

    deployment "nationalparks" successfully rolled out

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部