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 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
charts
where 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 install
command to install the chart on the cluster. See Installing the Helm CLI (helm) for more information about thehelm install
command. -
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
- Viewing ClusterServiceClasses and ClusterServicePlans
- Creating a ServiceInstance
- Binding the ServiceInstance to an application
- Unbinding an ServiceInstance
- Deleting a ServiceInstance
- 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:
-
Create a
broker.yaml
file, which contains the broker details. You must specify values for the brokername
and theurl
for the broker. Yourbroker.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
- Run the following command:
kubectl create -f broker.yaml
- Run the following command:
Viewing ClusterServiceClasses and ClusterServicePlans
Each service has a corresponding ServiceClass resource and can have one or more plans that are associated with it.
-
To display the registered services, run the following command:
kubectl get clusterserviceclasses
-
To display the registered plans, run the following command:
kubectl get clusterserviceplans
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:
-
Create a
instance.yaml
file for the service instance. Yourinstance.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
-
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:
-
Create the
binding.yaml
file that binds the service instance to an application. You must provide the bindingname
and asecretName
. Yourbinding.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
.
-
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.
-
To view the details of your
binding.yaml
file, 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-binding
is the name of the binding to remove.
Deleting a ServiceInstance
Delete the service instance. Run the following command:
kubectl delete -n test-ns serviceinstances ups-instance
ups-instance
is the name of the instance to delete.
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
ups-instance
is the name of the broker to delete.
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
ups-broker
is the name of the Helm deployment to delete.