Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Enable backing services in Kubernetes with kube-service-bindings

August 16, 2022
Costas Papastathis Michael Dawson
Related topics:
KubernetesNode.jsOperators
Related products:
Developer SandboxRed Hat OpenShift Container Platform

Share:

    This is the second part of a three-part series explaining how to bind easily to databases and other backing services from Node.js applications running in Kubernetes. The first article in the series, Connect to services on Kubernetes easily with kube-service-bindings, introduced the tools we use for this simplified integration: kube-service-bindings and the Service Binding Operator (SBO).

    In this article and the next, we'll set up a cluster with access to a MongoDB database. For our Kubernetes cluster, we use the Developer Sandbox for Red Hat OpenShift, a free service for developers to experiment and learn about open source tools.

    The articles use a MongoDB example hosted in GitHub to show you kube-service-bindings in action. This example will illustrate the process of deploying a Node.js and MongoDB application in OpenShift. The final step is to establish a connection between the processes with the Service Binding Operator and kube-service-bindings.

    Setting up an OpenShift cluster on the Red Hat Sandbox

    You are going to deploy your Node.js application in an OpenShift cluster. A quick and easy way that requires no local setup in your computer is to use Developer Sandbox for Red Hat OpenShift, a service hosted on the cloud and provided at no cost by Red Hat. After a few clicks to create a Red Hat account, you'll have an OpenShift cluster up and running, ready to use.

    To create your cluster:

    1. Visit the getting started page for the Developer Sandbox for Red Hat OpenShift.
    2. Click Launch your Developer Sandbox for Red Hat OpenShift.
    3. Register to create your Red Hat account.
    4. After completing your registration, you will be redirected to the initial page. Click Launch your Developer Sandbox for Red Hat OpenShift.
    5. Log in with the Red Hat account you created.
    6. Fill in the form with your personal information and click Submit.
    7. Confirm your mobile phone number via text. (Don't forget to click the Send Code button after filling in your phone number.)
    8. Click Start using your sandbox and your sandbox will start immediately.

    More information about the Developer Sandbox's resources and pre-installed software are available at the getting started page.

    Setting up a MongoDB database on MongoDB Atlas

    Now that your OpenShift cluster is up and running, you can create a database that your Node.js application will use to store its data. Luckily for us, the Developer Sandbox has Red Hat OpenShift Database Access built in. This lets you use an external service for hosting a database, outside of the OpenShift sandbox. Using an external database has several benefits:

    • Data is accessible no matter what the state is of the OpenShift cluster.
    • Other services outside of the OpenShift cluster are able to reach your database.
    • You can use an existing MongoDB database hosted on MongoDB Atlas.

    If you don't already have an account on MongoDB Atlas, register for one. There are several different levels of access, including a free one that is useful for learning projects like the one this article. After you register and sign in, select an organization, create a new project, and create a database as follows:

    1. On the upper left corner, next to the gear icon, expand the dropdown menu and choose View All Organizations (Figure 1).
      MongoDB Atlas provides a dropdown menu where you can view all organizations in your MongoDB Atlas account.
      Figure 1: MongoDB Atlas provides a dropdown menu where you can view all organizations in your MongoDB Atlas account.
    2. Click the Organizations button in the left sidebar and then click the organization in which you would like to create your database (Figure 2).
      On the dashboard of MongoDB Atlas, you can see all organizations in your MongoDB Atlas account.
      Figure 2: On the dashboard of MongoDB Atlas, you can see all organizations in your MongoDB Atlas account.
    3. Create a project by clicking Projects→New Project on the left sidebar (Figure 3).
      Under the Projects menu item, in the selected organization in MongoDB Atlas, you can see all available projects and create a new one.
      Figure 3: Under the Projects menu item, in the selected organization in MongoDB Atlas, you can see all available projects and create a new one.
    4. Type a name for your project, the select Next→ Create Project.
    5. Create a MongoDB database inside this project by clicking the Build Database button. On the next page, click the Create button on FREE plan→create cluster. Leave the values at their defaults.
    6. On the left sidebar, create a user for the MongoDB database by clicking Database Access→Add new Database user→Choose a username and password→Create user.
    7. At the bottom of the page, in the section Add a connection IP Address, set the field IP Address to the value 0.0.0.0/0, which will allow access from any IP address (Figure 4).
      Allowing accessing mongoDB cluster from any IP
      Figure 4: In the section "Add entries to your IP Access List", you are able to add an IP address from which you would like to access your cluster.  

       

    OpenShift Operators

    Once you have the OpenShift cluster and MongoDB database up and running, take a look at the Operators you'll use to integrate these processes. Your OpenShift cluster in the sandbox comes with several pre-installed Operators. To see currently installed Operators in the OpenShift cluster, switch to the Administrator perspective and expand Operators→Installed operators in the left sidebar. You should be able to see the list of all the installed Operators (Figure 4).

    The Developer Sandbox offers many Operators to integrate services with your application.
    Figure 4: The Developer Sandbox offers many Operators to integrate services with your application.

    For our needs, we are interested in the following Operators:

    • Red Hat OpenShift Database Access Operator: This integrates a database instance into an OpenShift cluster. The Operator gives your application in OpenShift access to a database hosted on an external service, such as MongoDB Atlas.
    • Service Binding Operator: As we discussed in the first article in this series, this follows the Service Binding specification to project the credentials of a backing service (here, your MongoDB instance) under a directory of a workload (here, your Node.js application).

    Set up access between OpenShift and a MongoDB database with the OpenShift Database Access Operator

    In this section, you'll give the OpenShift Database Access Operator access to the MongoDB Atlas organization in which you created a database, so that the Operator can configure, manage, and connect to the database instance you created previously.

    1. Choose a project you would like to work on by selecting, from the sidebar on the top left, Developer→Topology→Project. In the dropdown, select your project (Figure 5).
    2. Switch to the Administrator perspective on the top of the left sidebar.
    3. Expand the Data Services navigation menu at the bottom of the left sidebar and click Database Access.
    4. At the upper right, choose Configuration→Import Database Provider Account (Figure 6).
      Under the Configuration menu, you can import a database provider such as MongoDB Atlas.
      Figure 6: Under the Configuration menu, you can import a database provider such as MongoDB Atlas.
    5. On the form, select MongoDB Atlas Cloud Database on the Database provider drop-down menu. Then fill in the rest of the fields and click Import.

    At this point, by visiting Data Service→Database Access in the left sidebar, you should be able to see all database instances available to you in MongoDB Atlas (Figure 7).

    The database instances that you can reach from your cluster appear in the Database Access menu.
    Figure 7: The database instances that you can reach from your cluster appear in the Database Access menu.

    Elements of a binding between a Node.js application and a database

    This article has set up key building blocks of our application. In the next and final article of this series, we will connect the Node.js application and MongoDB database using kube-service-bindings and the Service Binding Operator.

    Last updated: September 19, 2023

    Recent Posts

    • How to enable Ansible Lightspeed intelligent assistant

    • Why some agentic AI developers are moving code from Python to Rust

    • Confidential VMs: The core of confidential containers

    • Benchmarking with GuideLLM in air-gapped OpenShift clusters

    • Run Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    What’s up next?

    The Node.js cheat sheet will help you master the most useful command-line flags to customize Node.js’s behavior. You’ll save time and energy looking up how to do everyday development tasks like executing scripts, debugging, and monitoring your Node.js applications.

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue