Creating 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. Register a broker to a service

  6. Viewing ClusterServiceClasses and ClusterServicePlans
  7. Creating a ServiceInstance
  8. Binding the ServiceInstance to an application
  9. Unbinding an ServiceInstance
  10. Deleting a ServiceInstance
  11. Deleting a ClusterServiceBroker

Register a broker to a service

Register a broker to a service. Before you can view the services and plans to create an instance of, you must register the broker to the service Catalog with the ClusterServiceBroker resource.

Register the broker to the service Catalog. Complete the following steps:

  1. Create 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:
      kubectl create -f broker.yaml
      

Viewing ClusterServiceClasses and ClusterServicePlans

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. You must create an instance of a service class before your applications can use it. Complete the following steps:

  1. Create a instance.yaml file for the service instance. 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. Run the following command:

     kubectl create -f instance.yaml
    

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
    

    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. Run 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. Run the following command:

  kubectl delete -n test-ns serviceinstances ups-instance

Deleting a ClusterServiceBroker

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

  kubectl delete clusterservicebrokers ups-broker

Clean up the service broker server

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

  helm delete --purge ups-broker