Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Service Binding Operator: The Operator in action

<p>&nbsp;</p> <quillbot-extension-portal></quillbot-extension-portal>

December 20, 2019
Shoubhik Bose Steve Speicher Len DiMaggio
Related topics:
JavaKubernetesNode.jsOperators
Related products:
Red Hat OpenShift

    In the previous article, we introduced the Service Binding Operator and explained how it functions. In this article, we'll look at a more advanced topic—custom environment variables—and walk through a typical usage scenario.

    Custom environment variables

    To make binding applications (e.g., legacy Java applications that depend on JDBS strings)  together with backing services more flexible, the Service Binding Operator supports the optional use of custom environment variables. To use custom environment variables, an application developer creates a ServiceBindingRequest that looks like the one shown in Figure 1:

    A ServiceBindingRequest that uses custom environment variables.
    Figure 1: A ServiceBindingRequest that uses custom environment variables.

    The custom environment variables, which in this example access a PostgreSQL database, are defined under customEnvVar and provide custom binding information for the application to bind with its needed backing services.

    The Service Binding Operator in action

    The best way to appreciate the features provided by the Service Binding Operator is to see them in action in a typical usage scenario. A set of example scenarios and operators that manage backing services is being developed in parallel with Service Binding Operator. (Links to these scenarios and backing operators are included in the final section of this article.)

    Let's use one of these scenarios and operators as an example. For the backing service, we will use a PostgreSQL database managed by this sample operator. For the application being bound to this backing service, we’ll use this Java, Spring Boot example application that implements a fruit inventory system.

    The documentation included with this and other example applications includes the full set of instructions, including admin tasks such as installing the Service Binding Operator and the backing service. In this illustration, we will focus on the steps taken by an application developer and the actions performed by the Service Binding Operator.

    Before we begin, we have to install the Service Binding Operator. The operator is available through the OperatorHub in the Red Hat OpenShift console's console's Administrative perspective as shown in Figure 1:

    Service Binding Operator actions

    The sequence of application developer steps and Service Binding Operator actions is as follows.

    Step 1: Import the app

    The application developer logs into the Red Hat OpenShift console's Developer perspective and creates a new app by referencing the application's source repo, as shown in Figure 3:

    Creating a new app in the Red Hat OpenShift console's Developer perspective.
    Figure 3: Creating a new app in the Red Hat OpenShift console's Developer perspective.

    Step 2: Create the database that the app will use

    The app developer now creates the database that the app will use, as shown in Figure 4. Note that at this point, the app and the backing service for the database are not bound together:

    Creating the database that the app will use.
    Figure 4: Creating the database that the app will use.

    OpenShift creates a Deployment for the app, starts a pod for the app, deploys the app, and provides a route to the app. At this point, the app is running but without its backing service. Our example app is constructed so that it can display its main page, but any attempt to create new entries in the fruit inventory fails and raises an alert due to the lack of a backing service database, as shown in Figure 5:

    A failed entry creates an alert.
    Figure 5: A failed entry creates an alert.

    Step 3: Show intent to bind by creating a ServiceBindingRequest

    At this point, the application developer signals the intent to bind the application together with a backing service by creating a ServiceBindingRequest. This ServiceBindingRequest includes custom environment variables that provide database connection information such as a username, password, and connection URL, plus a reference (ResourceRef) that refers to the backing database service by name, as shown in Figure 6:

    The YAML for this ServiceBindingRequest.
    Figure 6: The YAML for this ServiceBindingRequest.

    Step 4: The Service Binding Operator shares binding information with the application

    This information is collected by the Service Binding Operator into an intermediary secret, which is then shared with the application. The binding information corresponds to the application’s labels and backing service connection attributes.

    Step 5: The Service Binding Operator detects changes to the application’s Deployment

    The Service Binding Operator reconciles these changes. The entity in control of that pod (for example, a Deployment or DeploymentConfig) restarts the pod to have the changes take effect, resulting in what you see in Figure 7:

    The pod is now restarted.

    The application can now access the backing service database, as we see in Figure 8:

    The application in action.
    Figure 8: The application in action.

    What’s next?

    The Service Binding Operator is 100% open source. Download the code, kick the tires, provide feedback and ideas for new features, and contribute code!

    Resources

    • The Service Binding Operator GitHub repo.
    • A set of examples, each of which illustrates a usage scenario for the Service Binding Operator, is being developed in parallel with the Operator. Each example includes documentation and can be run either through the OpenShift web console or command-line client.
    • Sample Backing Service Operators are available here.
    Last updated: June 7, 2023

    Recent Posts

    • Preventing GPU waste: A guide to JIT checkpointing with Kubeflow Trainer on OpenShift AI

    • How to manage TLS certificates used by OpenShift GitOps operator

    • Configure a split disk on OpenShift Container Platform

    • Red Hat Enterprise Linux 10.2 and 9.8: Top features for developers

    • What GPU kernels mean for your distributed inference

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.