{"id":50074,"date":"2025-07-11T04:42:47","date_gmt":"2025-07-11T04:42:47","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=50074"},"modified":"2025-07-12T05:56:31","modified_gmt":"2025-07-12T05:56:31","slug":"openshift-lab-8-work-with-databases-in-openshift-using-the-oc-cli-tool","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/openshift-lab-8-work-with-databases-in-openshift-using-the-oc-cli-tool\/","title":{"rendered":"Openshift: Lab 8 &#8211; Work with databases in OpenShift using the oc CLI tool"},"content":{"rendered":"\n<p>In this lesson, you will learn how to create an instance of a database in the&nbsp;<a href=\"https:\/\/developers.redhat.com\/content-gateway\/link\/3881654\" target=\"_blank\" rel=\"noreferrer noopener\">Developer Sandbox&nbsp;<\/a>using the&nbsp;<code>oc<\/code>&nbsp;CLI tool, and ultimately bind a&nbsp;<a href=\"https:\/\/developers.redhat.com\/topics\/nodejs\" target=\"_blank\" rel=\"noopener\">Node.js<\/a>&nbsp;application to that database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What you need to know<\/h3>\n\n\n\n<p>In order to get full benefit from this lesson you need to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand how\u00a0<a href=\"https:\/\/developers.redhat.com\/topics\/kubernetes\" target=\"_blank\" rel=\"noopener\">Kubernetes<\/a>\u00a0is the foundational technology for\u00a0<a href=\"https:\/\/developers.redhat.com\/products\/openshift\/overview\" target=\"_blank\" rel=\"noopener\">OpenShift<\/a>.<\/li>\n\n\n\n<li>Know how to access the Developer Sandbox via web browser.<\/li>\n\n\n\n<li>Know how to use the\u00a0<code>oc<\/code>\u00a0CLI tool installed on your local computer to interact with a remote instance of the Developer Sandbox.<\/li>\n\n\n\n<li>Understand how environment variables provide information to an application at runtime.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">What you will learn<\/h3>\n\n\n\n<p>In this lesson you will learn:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>How to create an instance of a database in Developer Sandbox using the\u00a0<code>oc<\/code>\u00a0CLI tool.<\/li>\n\n\n\n<li>How to create an instance of a Node.js application from source code stored in GitHub using the\u00a0<code>oc<\/code>\u00a0CLI tool.<\/li>\n\n\n\n<li>How to bind the Node.js application to the database running in OpenShift\u00a0using the\u00a0<code>oc<\/code>\u00a0CLI tool.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Understand the demonstration scenario<\/h3>\n\n\n\n<p>The objective of this lesson is to demonstrate how to install and run a Node.js application bound to a database installed using the&nbsp;<code>oc<\/code>&nbsp;CLI tool. Both the Node.js application and the database will run in the Developer Sandbox.<\/p>\n\n\n\n<p>The Node.js application publishes a web page that allows users to retrieve a name at random, then store that random name in the database to which the application is bound. Also, the Node.js application web page displays a list of names stored in the database (Figure 1).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/foundations_1.41_figure_1.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/foundations_1.41_figure_1.png?itok=cs6t_J71\" alt=\"The Node.js demonstration application allows users to get, store, and list random names.\"\/><\/a><figcaption class=\"wp-element-caption\">Figure 1: The Node.js demonstration application allows users to get, store, and list random names.<\/figcaption><\/figure>\n\n\n\n<p>The demonstration scenario uses a MongoDB database which you will install using the&nbsp;<code>oc<\/code>&nbsp;CLI tool. Also, you will install the Node.js application in OpenShift using the&nbsp;<code>oc<\/code>&nbsp;CLI tool.<\/p>\n\n\n\n<p>The Node.js application has a server-side API that stores and retrieves data stored in the MongoDB database. This application also publishes a web page that is bound to the server-side API. Users interact with the page, and the page, in turn, interacts with the server-side API (Figure 2).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/foundations_1.41_figure_2.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/foundations_1.41_figure_2.png?itok=yjgjnWWq\" alt=\"The demonstration project binds a Node.js application running in the sandbox to an instance of a database that\u2019s also running in OpenShift.\"\/><\/a><figcaption class=\"wp-element-caption\">Figure 2: The demonstration project binds a Node.js application running in the sandbox to an instance of a database that\u2019s also running in OpenShift.<\/figcaption><\/figure>\n\n\n\n<p>Node.js binds to the MongoDB database by way of a connection URL that is created by OpenShift during the database installation process. The URL contains the username and password information. You will declare the username and password information when you install the MongoDB database.<\/p>\n\n\n\n<p>The Node.js application references the MongoDB connection URL to create a connection to the database. The way that the application knows the connection URL is by way of an environment variable that\u2019s created as part of the process of installing Node.js in the Developer Sandbox.<\/p>\n\n\n\n<p>In the sections that follow, you will learn how to install the MongoDB database and install the Node.js application along with the steps necessary to expose and consume the MongoDB connection URL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Get login credentials for the OpenShift web console<\/h3>\n\n\n\n<p>In order to use the&nbsp;<code>oc<\/code>&nbsp;CLI tool to access a remote instance of the Developer Sandbox, you need to get a special set of login credentials that are available from within the OpenShift web console.<\/p>\n\n\n\n<p>The following steps describe how to get the necessary login credentials:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to the web console for the\u00a0<a href=\"https:\/\/developers.redhat.com\/content-gateway\/link\/3881654\" target=\"_blank\" rel=\"noreferrer noopener\">Developer Sandbox<\/a>\u00a0and click the\u00a0<strong>question mark<\/strong>\u00a0in the upper right corner of the web console\u00a0(Figure 3, Callout 1).<\/li>\n\n\n\n<li>Select\u00a0<strong>Command line tools<\/strong>\u00a0from the drop-down. This action\u00a0opens the\u00a0<strong>Command line tools\u00a0<\/strong>web page\u00a0(Figure 3, Callout 2).<\/li>\n\n\n\n<li>Select\u00a0<strong>Copy command login<\/strong>\u00a0(Figure 3, Callout 3).\u00a0<a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/foundations_1.41_figure_3.png\" target=\"_blank\" rel=\"noopener\"><\/a>Figure 3: Access Command line tools by clicking the question mark in the upper right corner of the OpenShift web console.<\/li>\n\n\n\n<li>A page with the option\u00a0<strong>Display Token\u00a0<\/strong>will appear. Select\u00a0<strong>Display Token<\/strong>\u00a0(Figure 4, Callout 1).<\/li>\n\n\n\n<li>A page with\u00a0login credentials will appear. Copy the content of the\u00a0<strong>Display Token<\/strong>\u00a0field and paste it into the\u00a0<strong>Log in with this token\u00a0<\/strong>field\u00a0(Figure 4, Callout 2).\u00a0<a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/foundations_1.41_figure_4.png\" target=\"_blank\" rel=\"noopener\"><\/a>Figure 4: Clicking Display Token displays a page with login credentials.<\/li>\n\n\n\n<li>Go to a terminal running on your local machine and paste in the login text you copied, then select\u00a0<strong>Enter<\/strong>\u00a0to log in to the Developer Sandbox\u00a0(Figure 5).\u00a0<a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/foundations_1.41_figure_5.png\" target=\"_blank\" rel=\"noopener\"><\/a>Figure 5: With your login token, use the oc CLI tool to access the remote Developer Sandbox from your local machine.<\/li>\n<\/ol>\n\n\n\n<p>Once logged in, you can do work in the remote Developer Sandbox using the&nbsp;<code>oc<\/code>&nbsp;CLI tool.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install the database<\/h3>\n\n\n\n<p>Once you have logged into the Developer Sandbox using the&nbsp;<code>oc<\/code>&nbsp;CLI tool on your local machine, you are ready to install the database that the demonstration application will use. In this step, you will install an instance of MongoDB using an OpenShift template.<\/p>\n\n\n\n<p>While OpenShift includes templates for multiple databases, it does not include a template for MongoDB. That\u2019s not a problem; we can install it at the command line. First, use the following command to get the name of your project\u2013which, in Kubernetes-speak, is the namespace:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">oc <span class=\"hljs-keyword\">get<\/span> project<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>Now, use the namespace in the following commands:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">oc create -f \n<span class=\"hljs-attr\">https<\/span>:<span class=\"hljs-comment\">\/\/raw.githubusercontent.com\/openshift-labs\/starter-guides\/ocp-4.8\/mongodb-template.yaml -n {your-namespace}<\/span>\n\noc <span class=\"hljs-keyword\">new<\/span>-app --template=mongodb-ephemeral --param MONGODB_USER=genuser --param MONGODB_PASSWORD=password --param MONGODB_DATABASE=namegen --param NAMESPACE={your-namespace}\n\noc <span class=\"hljs-keyword\">import<\/span>-image mongodb:<span class=\"hljs-number\">3.6<\/span> \n--<span class=\"hljs-keyword\">from<\/span>=registry.access.redhat.com\/rhscl\/mongodb<span class=\"hljs-number\">-36<\/span>-rhel7 --confirm -n {your-namespace}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>About these parameters:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>--template=mongodb-persistent<\/code>\u00a0 declares the OpenShift template to use, in this case the\u00a0<code>mongodb-persistent<\/code>\u00a0template. The\u00a0<code>mongodb-persistent<\/code>\u00a0template creates a Kubernetes persistent volume claim (PVC) for storing database data. The data stored in the PVC will remain available even if the instance of the MongoDB database is removed from the Developer Sandbox.\u00a0<\/li>\n\n\n\n<li><code>--param=MONGODB_USER=genuser<\/code>\u00a0declares the name of the MongoDB user who will be reading and writing to the instance of the MongoDB database running in the Developer Sandbox.\u00a0<\/li>\n\n\n\n<li><code>--param=MONGODB_PASSWORD=password<\/code>\u00a0declares the password for the MongoDB user who will be reading and writing to the instance of the MongoDB database running in the Developer Sandbox.\u00a0<\/li>\n\n\n\n<li><code>--param=MONGODB_DATABASE=namegen<\/code>\u00a0declares the name of the database in the MongoDB instance that will be created to store data for the demonstration application.<\/li>\n<\/ul>\n\n\n\n<p>After you execute the command shown above, you will see output similar to this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">\n--&gt; Deploying template <span class=\"hljs-string\">\"openshift\/mongodb-persistent\"<\/span> to project &lt;your_redhat-login_name&gt;-dev\n\n     MongoDB\n\n     ---------\n\n     MongoDB database service, with persistent storage. <span class=\"hljs-keyword\">For<\/span> more information about using this template, including OpenShift considerations, see documentation in the upstream repository: https:<span class=\"hljs-comment\">\/\/github.com\/sclorg\/mongodb-container.<\/span>\n\n     NOTE: Scaling to more than one replica is not supported. You must have persistent volumes available in your cluster to <span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">this<\/span> <span class=\"hljs-title\">template<\/span>.\n\n     <span class=\"hljs-title\">The<\/span> <span class=\"hljs-title\">following<\/span> <span class=\"hljs-title\">service<\/span>(<span class=\"hljs-title\">s<\/span>) <span class=\"hljs-title\">have<\/span> <span class=\"hljs-title\">been<\/span> <span class=\"hljs-title\">created<\/span> <span class=\"hljs-title\">in<\/span> <span class=\"hljs-title\">your<\/span> <span class=\"hljs-title\">project<\/span>: <span class=\"hljs-title\">mongodb<\/span>.\n\n            <span class=\"hljs-title\">Username<\/span>: <span class=\"hljs-title\">genuser<\/span>\n\n            <span class=\"hljs-title\">Password<\/span>: <span class=\"hljs-title\">password<\/span>\n\n       <span class=\"hljs-title\">Database<\/span> <span class=\"hljs-title\">Name<\/span>: <span class=\"hljs-title\">namegen<\/span>\n\n      <span class=\"hljs-title\">Connection<\/span> <span class=\"hljs-title\">URL<\/span>: <span class=\"hljs-title\">mongodb<\/span>:\/\/<span class=\"hljs-title\">genuser<\/span>:<span class=\"hljs-title\">password<\/span>@<span class=\"hljs-title\">mongodb<\/span>\/<span class=\"hljs-title\">namegen<\/span>   \n\n     <span class=\"hljs-title\">For<\/span> <span class=\"hljs-title\">more<\/span> <span class=\"hljs-title\">information<\/span> <span class=\"hljs-title\">about<\/span> <span class=\"hljs-title\">using<\/span> <span class=\"hljs-title\">this<\/span> <span class=\"hljs-title\">template<\/span>, <span class=\"hljs-title\">including<\/span> <span class=\"hljs-title\">OpenShift<\/span> <span class=\"hljs-title\">considerations<\/span>, <span class=\"hljs-title\">see<\/span> <span class=\"hljs-title\">documentation<\/span> <span class=\"hljs-title\">in<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">upstream<\/span> <span class=\"hljs-title\">repository<\/span>: <span class=\"hljs-title\">https<\/span>:\/\/<span class=\"hljs-title\">github<\/span>.<span class=\"hljs-title\">com<\/span>\/<span class=\"hljs-title\">sclorg<\/span>\/<span class=\"hljs-title\">mongodb<\/span>-<span class=\"hljs-title\">container<\/span>.\n\n     * <span class=\"hljs-title\">With<\/span> <span class=\"hljs-title\">parameters<\/span>:\n\n        * <span class=\"hljs-title\">Memory<\/span> <span class=\"hljs-title\">Limit<\/span>=512<span class=\"hljs-title\">Mi<\/span>\n\n        * <span class=\"hljs-title\">Namespace<\/span>=<span class=\"hljs-title\">openshift<\/span>\n\n        * <span class=\"hljs-title\">Database<\/span> <span class=\"hljs-title\">Service<\/span> <span class=\"hljs-title\">Name<\/span>=<span class=\"hljs-title\">mongodb<\/span>\n\n        * <span class=\"hljs-title\">MongoDB<\/span> <span class=\"hljs-title\">Connection<\/span> <span class=\"hljs-title\">Username<\/span>=<span class=\"hljs-title\">genuser<\/span>\n\n        * <span class=\"hljs-title\">MongoDB<\/span> <span class=\"hljs-title\">Connection<\/span> <span class=\"hljs-title\">Password<\/span>=<span class=\"hljs-title\">password<\/span>\n\n        * <span class=\"hljs-title\">MongoDB<\/span> <span class=\"hljs-title\">Database<\/span> <span class=\"hljs-title\">Name<\/span>=<span class=\"hljs-title\">namegen<\/span>\n\n        * <span class=\"hljs-title\">MongoDB<\/span> <span class=\"hljs-title\">Admin<\/span> <span class=\"hljs-title\">Password<\/span>=0<span class=\"hljs-title\">SNxmy1woMqOuFye<\/span> # <span class=\"hljs-title\">generated<\/span>\n\n        * <span class=\"hljs-title\">Volume<\/span> <span class=\"hljs-title\">Capacity<\/span>=1<span class=\"hljs-title\">Gi<\/span>\n\n        * <span class=\"hljs-title\">Version<\/span> <span class=\"hljs-title\">of<\/span> <span class=\"hljs-title\">MongoDB<\/span> <span class=\"hljs-title\">Image<\/span>=3.6\n\n--&gt; <span class=\"hljs-title\">Creating<\/span> <span class=\"hljs-title\">resources<\/span> ...\n\n    <span class=\"hljs-title\">secret<\/span> \"<span class=\"hljs-title\">mongodb<\/span>\" <span class=\"hljs-title\">created<\/span>\n\n    <span class=\"hljs-title\">service<\/span> \"<span class=\"hljs-title\">mongodb<\/span>\" <span class=\"hljs-title\">created<\/span>\n\n    <span class=\"hljs-title\">persistentvolumeclaim<\/span> \"<span class=\"hljs-title\">mongodb<\/span>\" <span class=\"hljs-title\">created<\/span>\n\n    <span class=\"hljs-title\">deploymentconfig<\/span>.<span class=\"hljs-title\">apps<\/span>.<span class=\"hljs-title\">openshift<\/span>.<span class=\"hljs-title\">io<\/span> \"<span class=\"hljs-title\">mongodb<\/span>\" <span class=\"hljs-title\">created<\/span>\n\n--&gt; <span class=\"hljs-title\">Success<\/span>\n\n    <span class=\"hljs-title\">Application<\/span> <span class=\"hljs-title\">is<\/span> <span class=\"hljs-title\">not<\/span> <span class=\"hljs-title\">exposed<\/span>. <span class=\"hljs-title\">You<\/span> <span class=\"hljs-title\">can<\/span> <span class=\"hljs-title\">expose<\/span> <span class=\"hljs-title\">services<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">outside<\/span> <span class=\"hljs-title\">world<\/span> <span class=\"hljs-title\">by<\/span> <span class=\"hljs-title\">executing<\/span> <span class=\"hljs-title\">one<\/span> <span class=\"hljs-title\">or<\/span> <span class=\"hljs-title\">more<\/span> <span class=\"hljs-title\">of<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">commands<\/span> <span class=\"hljs-title\">below<\/span>:\n\n     '<span class=\"hljs-title\">oc<\/span> <span class=\"hljs-title\">expose<\/span> <span class=\"hljs-title\">service<\/span>\/<span class=\"hljs-title\">mongodb<\/span>' \n\n    <span class=\"hljs-title\">Run<\/span> '<span class=\"hljs-title\">oc<\/span> <span class=\"hljs-title\">status<\/span>' <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">view<\/span> <span class=\"hljs-title\">your<\/span> <span class=\"hljs-title\">app<\/span>.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>After the MongoDB database is installed and running in the Developer Sandbox, you will install a Node.js application that uses the MongoDB database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install the Node.js application<\/h3>\n\n\n\n<p>Run the following steps in the terminal window of your local machine to install the demonstration application in the Developer Sandbox. Copy and paste the following&nbsp;<code>oc new app<\/code>&nbsp;command into the terminal on your local machine:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">oc <span class=\"hljs-keyword\">new<\/span>-app https:<span class=\"hljs-comment\">\/\/github.com\/redhat-developer-demos\/namegen --name=namegen-app --env=MONGODB_URL=mongodb:\/\/genuser:password@mongodb\/namegen<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>About these parameters:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>https:\/\/github.com\/redhat-developer-demos\/namegen<\/code>\u00a0is the location of the source code where the Node.js application is stored on GitHub. OpenShift will retrieve the source code from GitHub and use it to create a Linux container that will be part of the\u00a0<a href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/deployment\/\" target=\"_blank\" rel=\"noopener\">Kubernetes Deployment<\/a>\u00a0under which the application can be run in the Developer Sandbox.<\/li>\n\n\n\n<li><code>--name=namegen-app<\/code>\u00a0declares the name that will be associated with the Node.js application inside the Developer Sandbox\/Openshift cluster.<\/li>\n\n\n\n<li><code>--env=MONGODB_URL=mongodb:\/\/genuser:password@mongodb\/namegen<\/code>\u00a0uses the\u00a0<code>\u2013env<\/code>\u00a0command-line option to declare the environment variable\u00a0<code>MONGODB_URL<\/code>\u00a0which will be injected into each container running the deployment of the Node.js application running in the Developer Sandbox\/OpenShift cluster. This environment variable describes the connection URL that the Node.js application uses to connect to the instance of MongoDB that you already installed.<\/li>\n<\/ul>\n\n\n\n<p>After you execute the command shown above, you\u2019ll see output similar to this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">--&gt; Found image dfd08e2 (<span class=\"hljs-number\">7<\/span> months old) in image stream <span class=\"hljs-string\">\"openshift\/nodejs\"<\/span> under tag <span class=\"hljs-string\">\"16-ubi8\"<\/span> <span class=\"hljs-keyword\">for<\/span> <span class=\"hljs-string\">\"nodejs\"<\/span>\n\n    Node.js <span class=\"hljs-number\">16<\/span> \n\n    ---------- \n\n    Node.js <span class=\"hljs-number\">16<\/span> available <span class=\"hljs-keyword\">as<\/span> container is a base platform <span class=\"hljs-keyword\">for<\/span> building <span class=\"hljs-keyword\">and<\/span> running various Node.js <span class=\"hljs-number\">16<\/span> applications <span class=\"hljs-keyword\">and<\/span> frameworks. Node.js is a platform built on Chrome<span class=\"hljs-string\">'s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I\/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.\n\n    Tags: builder, nodejs, nodejs16\n\n    * The source repository appears to match: nodejs\n\n    * A source build using source code from https:\/\/github.com\/redhat-developer-demos\/namegen will be created\n\n      * The resulting image will be pushed to image stream tag \"namegen-app:latest\"\n\n      * Use '<\/span>oc start-build<span class=\"hljs-string\">' to trigger a new build\n\n\n--&gt; Creating resources ...\n\n    imagestream.image.openshift.io \"namegen-app\" created\n\n    buildconfig.build.openshift.io \"namegen-app\" created\n\n    deployment.apps \"namegen-app\" created\n\n    service \"namegen-app\" created\n\n--&gt; Success\n\n    Build scheduled, use '<\/span>oc logs -f buildconfig\/namegen-app<span class=\"hljs-string\">' to track its progress.\n\n    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:\n\n     '<\/span>oc expose service\/namegen-app<span class=\"hljs-string\">' \n\n    Run '<\/span>oc status<span class=\"hljs-string\">' to view your app.<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Verify the installation<\/h3>\n\n\n\n<p>At this point, the MongoDB instance and Node.js application are installed and running in the Developer Sandbox. To verify that they are indeed up and running, copy and paste the following&nbsp;<code>oc status<\/code>&nbsp;command into the terminal on your local machine:&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">oc status<\/code><\/span><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>You will see output similar to the following, which indicates that both the MongoDB instance and Node.js&nbsp;<code>namegen<\/code>&nbsp;application are up and running:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">In project &lt;red_hat_username&gt;-dev on server https:<span class=\"hljs-comment\">\/\/api.sandbox.x8i5.p1.openshiftapps.com:6443<\/span>\n\nsvc\/mongodb - <span class=\"hljs-number\">172.30<\/span><span class=\"hljs-number\">.58<\/span><span class=\"hljs-number\">.199<\/span>:<span class=\"hljs-number\">27017<\/span>\n\n  dc\/mongodb deploys openshift\/mongodb:<span class=\"hljs-number\">3.6<\/span> \n\n    deployment <span class=\"hljs-comment\">#1 deployed 20 minutes ago - 1 pod<\/span>\n\nhttp:<span class=\"hljs-comment\">\/\/namegen-app-&lt;red_hat_username&gt;-dev.apps.sandbox.x8i5.p1.openshiftapps.com to pod port 8080-tcp (svc\/namegen-app)<\/span>\n\n  deployment\/namegen-app deploys istag\/namegen-app:latest &lt;-\n\n    bc\/namegen-app source builds https:<span class=\"hljs-comment\">\/\/github.com\/redhat-developer-demos\/namegen on openshift\/nodejs:16-ubi8 <\/span>\n\n    deployment <span class=\"hljs-comment\">#2 running for 20 minutes - 1 pod<\/span>\n\n    deployment <span class=\"hljs-comment\">#1 deployed 20 minutes ago<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>You are now ready to expose the&nbsp;<code>namegen<\/code>&nbsp;application to the internet so that it can be used in a web browser.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Expose the Node.js application to the Internet<\/h3>\n\n\n\n<p>To&nbsp;expose the&nbsp;<code>namegen<\/code>&nbsp;application to the Internet by using the&nbsp;<code>oc expose<\/code>&nbsp;command, copy and paste the following&nbsp;<code>oc expose<\/code>&nbsp;command into the terminal on your local machine:&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">oc expose service\/namegen-app<\/code><\/span><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>You will get output similar to the following:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">route.route.openshift.io\/namegen-app exposed<\/code><\/span><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>Running&nbsp;<code>oc expose<\/code>&nbsp;creates an OpenShift route. An OpenShift route is associated with a URL that allows access to the Node.js&nbsp;<code>namegen<\/code>&nbsp;application from the internet.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exercise the demonstration application<\/h3>\n\n\n\n<p>To exercise the demonstration application, use the&nbsp;<code>oc get&nbsp;route<\/code>&nbsp;command to determine the URL for the Node.js&nbsp;<code>namegen<\/code>&nbsp;application. Run the following&nbsp;<code>oc get&nbsp;route<\/code>&nbsp;command into the terminal on your local machine:&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">oc <span class=\"hljs-keyword\">get<\/span> route<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>You will get output similar to the following. Notice that the URL to the application is reported by the string in the&nbsp;<strong>PATH<\/strong>&nbsp;column:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">NAME          HOST\/PORT                                                         PATH   SERVICES      PORT       TERMINATION   WILDCARD\n\nnamegen-app   namegen-app-<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">your_redhat-login_name<\/span>&gt;<\/span>-dev.apps.sandbox.x8i5.p1.openshiftapps.com          namegen-app   8080-tcp                 None\n\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a>Copy snippet<\/a><\/p>\n\n\n\n<p>Now, copy the URL reported in the output from&nbsp;<code>oc get route<\/code>&nbsp;into the address bar on your browser. The URL you copy will be similar to the following:<\/p>\n\n\n\n<p><code>namegen-app--dev.apps.sandbox.x8i5.p1.openshiftapps.com<\/code><\/p>\n\n\n\n<p>About the parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>your_redhat-login_name<\/code>\u00a0is your login name.<\/li>\n\n\n\n<li><code>apps.sandbox.x8i5.p1.openshiftapps.com<\/code>\u00a0represents a unique domain name for the particular Developer Sandbox instance. In this case, the domain name is special to the Developer Sandbox user taking this lesson.<\/li>\n<\/ul>\n\n\n\n<p>Copying the URL that\u2019s reported by&nbsp;<code>oc get&nbsp;route<\/code>&nbsp;into a web browser will render the&nbsp;<strong>Random Name Generator and Save<\/strong>&nbsp;window (Figure 6).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/foundations_1.41_figure_6.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/foundations_1.41_figure_6.png?itok=Sj3uk8pS\" alt=\"The Node.js demonstration application generates a random name on demand and then adds the name to a list of names stored in the MongoDB database.\"\/><\/a><figcaption class=\"wp-element-caption\">Figure 6: The Node.js demonstration application generates a random name on demand and then adds the name to a list of names stored in the MongoDB database.<\/figcaption><\/figure>\n\n\n\n<p>The Node.js&nbsp;<code>namegen<\/code>&nbsp;application is now up and running. You can exercise the application by selecting&nbsp;<strong>Get Random Name<\/strong>.<\/p>\n\n\n\n<p>An automatically generated random name will appear. Select&nbsp;<strong>Save Name<\/strong>&nbsp;to add the newly created random name to the list of names.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<p>In this lesson, you learned how to use the&nbsp;<code>oc<\/code>&nbsp;CLI tool to install an instance of MongoDB and a Node.js application named&nbsp;<code>namegen<\/code>&nbsp;into the Developer Sandbox and installed the MongoDB instance from an&nbsp;<a href=\"https:\/\/docs.openshift.com\/container-platform\/4.7\/openshift_images\/using-templates.html\" target=\"_blank\" rel=\"noopener\">OpenShift template<\/a>&nbsp;available in the OpenShift Developer Catalog. You also installed the Node.js application from source code stored on GitHub and learned how to configure both the&nbsp; MongoDB instance and Node.js application by declaring command-line options.<\/p>\n\n\n\n<p>In addition, you used the&nbsp;<code>oc expose<\/code>&nbsp;command to create a route to the Node.js&nbsp;<code>namegen<\/code>&nbsp;application that\u2019s accessible from the internet. Then you used the&nbsp;<code>oc get route<\/code>&nbsp;command to discover the URL created by the&nbsp;<code>oc expose<\/code>&nbsp;command.<\/p>\n\n\n\n<p>Finally, you exercised the Node.js application by pasting the application\u2019s URL into a web browser and interacting with the application&#8217;s web page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this lesson, you will learn how to create an instance of a database in the&nbsp;Developer Sandbox&nbsp;using the&nbsp;oc&nbsp;CLI tool, and ultimately bind a&nbsp;Node.js&nbsp;application to that database. What you need to&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5153],"tags":[],"class_list":["post-50074","post","type-post","status-publish","format-standard","hentry","category-openshift"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=50074"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50074\/revisions"}],"predecessor-version":[{"id":50075,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50074\/revisions\/50075"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=50074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=50074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=50074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}