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

Service Binding Operator: The Operator in action

 

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

Share:

    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

    • Profiling vLLM Inference Server with GPU acceleration on RHEL

    • Network performance in distributed training: Maximizing GPU utilization on OpenShift

    • Clang bytecode interpreter update

    • How Red Hat has redefined continuous performance testing

    • Simplify OpenShift installation in air-gapped environments

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

    Red Hat legal and privacy links

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

    Report a website issue