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 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:
-
Optionally, you can create a new Helm repository named
chartswhere you can download the service broker. See Adding a Helm repository for the procedure. -
If you created a new repository, clone the repository to download the service broker into the new Helm repository.
-
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 installcommand to install the chart on the cluster. See Installing the Helm CLI (helm) for more information about thehelm installcommand. -
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 -
Registering a service broker to the IBM Cloud Private Catalog
- Viewing ServiceClasses and ServicePlans
- Creating a ServiceInstance
- Binding the ServiceInstance to an application
- Unbinding an ServiceInstance
- Deleting a ServiceInstance
- 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:
-
Create a ServiceBroker resource by creating a
broker.yamlfile, which contains the broker details. You must specify values for the brokernameand theurlfor the broker. Yourbroker.yamlfile 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-
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:
-
Create a ServiceBroker resource by creating a
ns-broker.yamlfile, which contains the broker details. You must specify values for the brokername,namespace, andurl. Yourns-broker.yamlfile 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 -
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.
-
To display the registered service classes, run the following command:
-
Display the registered service classes for the cluster-level brokers:
kubectl get clusterserviceclasses -
Display the registered service classes for the namespace-level brokers:
kubectl get serviceclasses -n ns-broker
-
-
To display the registered service plans, run the following command:
-
Display the registered service plans for the cluster-level brokers:
kubectl get clusterserviceplans -
Display the registered service plans for the namespace-level brokers:
kubectl get serviceplans -n ns-broker
-
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
-
Create a ServiceInstance resource for your cluster-level broker in the
instance.yamlfile. Yourinstance.yamlfile 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 -
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
-
Create a ServiceInstance resource for your namespace-level broker your
instance.yamlfile. Yourinstance.yamlfile 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 -
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:
-
Get the name of the namespace, where the ServiceInstance resource is located:
kubectl get serviceinstance -n test-ns -
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
Binding the ServiceInstance to an application
To bind the ServiceInstance to an application, Complete the following steps:
-
Create the
binding.yamlfile that binds the service instance to an application. You must provide the bindingnameand asecretName. Yourbinding.yamlfile 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-instanceNote: The value for the
namespaceparameter of thebinding.yamlfile 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
.
-
Create a
binding.yamlfile by running the following command:kubectl create -f binding.yamlThe service catalog controller creates a Kubernetes secret that contains the connection details and credentials for the service instance.
-
To view the details of your
binding.yamlfile, run the following command:kubectl get servicebindings service_binding -o yaml -
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
ups-bindingis the name of the binding to remove.
Deleting a ServiceInstance
Delete the service instance by running the following command:
kubectl delete -n test-ns serviceinstances ups-instance
ups-instanceis the name of the instance to delete.
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
ups-brokeris the name of the cluster-level service 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
ups-brokeris the name of the namespace-level service broker to delete.
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
-
ups-brokeris the name of the Helm deployment to delete.Important: You must complete the deletion process in the following order: unbind your service instance, delete your service instance, delete your service broker, and delete your Helm deployment.