2.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

  1. From the Quick create ( fa plus circle ) menu in the upper right corner, click Container images.
  2. Select Image name from external registry and enter registry.redhat.io/rhmap47/mongodb.
  3. In the Runtime icon field, search for and select mongodb.
  4. Scroll to the General section.
  5. In the Application name field, enter national-parks-app.
  6. In the Name field, enter mongodb-nationalparks.
  7. Scroll to the Deploy section.
  8. In the Resource type field, ensure that Deployment is selected.
  9. Click Show advanced Deployment option.
  10. Under Environment variables (runtime only), add the following names and values:

    Expand
    表 2.1. Environment variable names and values
    NameValue

    MONGODB_USER

    mongodb

    MONGODB_PASSWORD

    mongodb

    MONGODB_DATABASE

    mongodb

    MONGODB_ADMIN_PASSWORD

    mongodb

    提示

    Click Add value to add each additional environment variable.

  11. In the Advanced options section, clear Create a route.

    The database application does not need to be accessed externally, so a route is not required.

  12. Click Create.

    You are redirected to the Topology page where you can see the mongodb-nationalparks deployment in the national-parks-app application.

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. Navigate to Workloads Secrets.
  2. Click Create Key/value secret.
  3. In the Secret name field, enter nationalparks-mongodb-parameters.
  4. Enter the following values for Key and Value:

    Expand
    表 2.2. Secret keys and values
    KeyValue

    DATABASE_SERVICE_NAME

    mongodb-nationalparks

    MONGODB_USER

    mongodb

    MONGODB_PASSWORD

    mongodb

    MONGODB_DATABASE

    mongodb

    MONGODB_ADMIN_PASSWORD

    mongodb

    提示

    Click Add key/value to add each additional key/value pair.

  5. Click Create.
  6. Click Add Secret to workload.
  7. From the Add this secret to workload list, select nationalparks.
  8. Click Save.

    This change in configuration triggers a new rollout of the nationalparks deployment with the environment variables properly injected.

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部