1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/getting-started-cli-creating-secret.adoc
2025-04-11 13:35:22 +00:00

51 lines
2.2 KiB
Plaintext

// Module included in the following assemblies:
//
// * tutorials/dev-app-cli.adoc
:_mod-docs-content-type: PROCEDURE
[id="getting-started-cli-creating-secret_{context}"]
= Providing access to the database by creating a secret
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, {product-title} 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
. Create the secret with the required database access information by running the following command:
+
[source,terminal]
----
$ 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
----
. Import the environment from the secret to the `nationalparks` workload by running the following command:
+
[source,terminal]
----
$ oc set env --from=secret/nationalparks-mongodb-parameters deploy/nationalparks
----
. 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:
+
[source,terminal]
----
$ oc rollout status deployment nationalparks
----
+
.Example output
+
[source,terminal]
----
deployment "nationalparks" successfully rolled out
----