Managing a service broker resource from the command line interface (CLI)

You can deploy a service broker to view the available services and plans, create an instance from the available services and plans, and create bindings to connect to the service instance.

You can deploy a community sample service broker to test the function, or install your own service broker that follows the Open Service Broker API specification for your own requirements.

You can use the Kubernetes ups_broker sample service broker Opens in a new tab as an easy way to look at the service broker function. You can deploy it on to your cluster as a Helm chart by completing the following steps:

  1. Optionally, you can create a new Helm repository named charts where you can download the service broker. See Adding a Helm repository for the procedure.

  2. If you created a new repository, clone the repository to download the service broker into the new Helm repository.

  3. If you chose not to create a new repository, you can download the service broker chart into an existing Helm repository. If you don't want to use a Helm repository, you can download the chart and use the helm install command to install the chart on the cluster. See Installing the Helm CLI (helm) for more information about the helm install command.

  4. Run the following Helm command in the Helm CLI to deploy the service broker:

    helm install charts/ups-broker --name ups-broker --namespace ups-broker
    
  5. Registering a service broker to the IBM Cloud Private Catalog

  6. Viewing ServiceClasses and ServicePlans
  7. Creating a ServiceInstance
  8. Binding the ServiceInstance to an application
  9. Unbinding an ServiceInstance
  10. Deleting a ServiceInstance
  11. Deleting a ServiceBroker

Registering a service broker to the IBM Cloud Private Service Catalog

You can register a broker to a service in your cluster or in your namespace. Before you can view the services and plans to create an instance of, you must register the broker to the service Catalog with the ServiceBroker resource.

Registering a cluster-level service broker

Register a cluster-level service broker to the service Catalog. Complete the following steps:

  1. Create a ServiceBroker resource by creating a broker.yaml file, which contains the broker details. You must specify values for the broker name and the url for the broker. Your broker.yaml file might resemble the following content:

     apiVersion: servicecatalog.k8s.io/v1beta1
     kind: ClusterServiceBroker
     metadata:
       name: ups-broker
     spec:
       url: http://ups-broker-ups-broker.ups-broker.svc.cluster.local
    
    1. Run the following command to create your cluster-level ServiceBroker resource:

      kubectl create -f broker.yaml
      

A cluster-level broker is created.

Registering a namespace-level service broker

Complete the following steps to register a namespace-level service broker to the service Catalog:

  1. Create a ServiceBroker resource by creating a ns-broker.yaml file, which contains the broker details. You must specify values for the broker name, namespace, and url. Your ns-broker.yaml file might resemble the following content:

     apiVersion: servicecatalog.k8s.io/v1beta1
     kind: ServiceBroker
     metadata:
       name: ups-broker
       namespace: ns-broker
     spec:
       url: http://ups-broker-ups-broker.default.svc.cluster.local
    
  2. Run the following command to create your namespace-level ServiceBroker resource:

       kubectl create -f ns-broker.yaml
    

A namespace-level broker is created.

Viewing ServiceClasses and ServicePlans

Each service has a corresponding ServiceClass resource and can have one or more plans that are associated with it.

Creating a ServiceInstance

Create a ServiceInstance resource by creating a instance.yaml file for a service broker. You must create an instance of a service class before your applications can use it. Complete the following steps:

Creating a ServiceInstance for your cluster-level broker

  1. Create a ServiceInstance resource for your cluster-level broker in the instance.yaml file. Your instance.yaml file might resemble the following content:

       apiVersion: servicecatalog.k8s.io/v1beta1
       kind: ServiceInstance
       metadata:
         name: ups-instance
         namespace: test-ns
       spec:
         clusterServiceClassExternalName: user-provided-service
         clusterServicePlanExternalName: default
         parameters:
           credentials:
             name: root
             password: letmein
    
  2. Create the instance by running the following command:

       kubectl create -f instance.yaml
    

A service instance is created for your cluster service broker.

Creating a ServiceInstance for your namespace-level broker

  1. Create a ServiceInstance resource for your namespace-level broker your instance.yaml file. Your instance.yaml file might resemble the following content:

       apiVersion: servicecatalog.k8s.io/v1beta1
       kind: ServiceInstance
       metadata:
         name: ups-ns-instance
         namespace: ns-broker
       spec:
         serviceClassExternalName: user-provided-service
         servicePlanExternalName: default
         parameters:
           credentials:
             name: root
             password: letmein
    
  2. Create the instance by running the following command:

       kubectl create -f ns-instance.yaml
    

A service instance is created for your namespace service broker.

Viewing the ServiceInstance

You can view your ServiceInstance resources from the command line interface (CLI).

Complete the following steps to view your ServiceInstance resources:

  1. Get the name of the namespace, where the ServiceInstance resource is located:

     kubectl get serviceinstance -n test-ns
    
  2. Run the following command to view the details of your resource:

     kubectl get serviceinstance ups-instance -n test-ns -o yaml
    

You can also view your resources from the management console. For more information, see Managing the Service Catalog resources from the IBM Cloud Private management console Opens in a new tab

Binding the ServiceInstance to an application

To bind the ServiceInstance to an application, Complete the following steps:

  1. Create the binding.yaml file that binds the service instance to an application. You must provide the binding name and a secretName. Your binding.yaml file might resemble the following content:

     apiVersion: servicecatalog.k8s.io/v1beta1
     kind: ServiceBinding
     metadata:
       name: <binding_name>
       namespace: test-ns
     spec:
       secretName: <secret_name>
       instanceRef:
         name: ups-instance
    

    Note: The value for the namespace parameter of the binding.yaml file must be the same value as the service instance namespace. The service binding YAML example is for cluster-level resources, but namespace-level YAML files follow the same format.

    For more details the pod selector labels in the Kubernetes documentation, see Labels and Selectors Opens in a new tab.

  2. Create a binding.yaml file by running the following command:

     kubectl create -f binding.yaml
    

    The service catalog controller creates a Kubernetes secret that contains the connection details and credentials for the service instance.

  3. To view the details of your binding.yaml file, run the following command:

     kubectl get servicebindings service_binding -o yaml
    
  4. View the secret details to connect to the application. Run the following command:

     kubectl get secrets <secret_name> -o yaml
    
    • <secret_name> is the secret name that is used in the binding. Your <secret_name> might resemble the following content:

      apiVersion: v1
      data:
      . . Secret data to connect to the database instance . .
      kind: Secret
      metadata:
      . . metadata parameters and values . .
      type: Opaque
      

Unbinding an ServiceInstance

You must delete the ServiceBinding that you created before you unbind an instance from an application. After you delete a binding, the secret that the binding uses is also deleted.

To unbind an instance, run the following command:

  kubectl delete -n test-ns servicebindings ups-binding

Deleting a ServiceInstance

Delete the service instance by running the following command:

  kubectl delete -n test-ns serviceinstances ups-instance

Deleting a ServiceBroker

To delete a ClusterServiceBroker you must unregister the broker. To unregister the broker, run the following command:

  kubectl delete clusterservicebrokers ups-broker

To delete a NamespaceServiceBroker you must unregister the broker. To unregister the broker, run the following command:

  kubectl delete servicebrokers ups-broker -n ns-broker

Deleting a Helm deployment

You must delete the Helm deployment when you clean up the service broker server. To delete the Helm deployment, run the following command:

  helm delete --purge ups-broker