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
parksmapfront-end application. -
You have deployed the
nationalparksback-end application.
Procedure
-
From the Quick create (
) menu in the upper right corner, click Container images.
-
Select Image name from external registry and enter
registry.redhat.io/rhmap47/mongodb. -
In the Runtime icon field, search for and select
mongodb. - Scroll to the General section.
-
In the Application name field, enter
national-parks-app. -
In the Name field, enter
mongodb-nationalparks. - Scroll to the Deploy section.
- In the Resource type field, ensure that Deployment is selected.
- Click Show advanced Deployment option.
Under Environment variables (runtime only), add the following names and values:
Expand 表 2.1. Environment variable names and values Name Value MONGODB_USERmongodbMONGODB_PASSWORDmongodbMONGODB_DATABASEmongodbMONGODB_ADMIN_PASSWORDmongodb提示Click Add value to add each additional environment variable.
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.
Click Create.
You are redirected to the Topology page where you can see the
mongodb-nationalparksdeployment in thenational-parks-appapplication.
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
nationalparksback-end application. -
You have deployed the
mongodb-nationalparksdatabase application.
Procedure
-
Navigate to Workloads
Secrets. -
Click Create
Key/value secret. -
In the Secret name field, enter
nationalparks-mongodb-parameters. Enter the following values for Key and Value:
Expand 表 2.2. Secret keys and values Key Value DATABASE_SERVICE_NAMEmongodb-nationalparksMONGODB_USERmongodbMONGODB_PASSWORDmongodbMONGODB_DATABASEmongodbMONGODB_ADMIN_PASSWORDmongodb提示Click Add key/value to add each additional key/value pair.
- Click Create.
- Click Add Secret to workload.
-
From the Add this secret to workload list, select
nationalparks. Click Save.
This change in configuration triggers a new rollout of the
nationalparksdeployment with the environment variables properly injected.