After completing this section, you should be able to discover applications deployed on OpenShift automatically.
With service discovery, you can import products and backends from existing Red Hat OpenShift Container Platform (RHOCP) services. Service discovery also enables you to update the ActiveDocs OpenAPI specification.
To use service discovery:
Enable it in the system configmap in the project where 3scale is installed.
Add metadata to the services to enable service discovery and configure the service information.
Make sure that 3scale has access to the services that you want to import.
You can enable or disable service discovery globally by editing the system configmap in the 3scale project. To do this you must edit the configmap service_discovery.yml entry, setting the value production.enabled to true.
If you installed 3scale by using the operator method then service discovery is enabled by default.
You can verify that it is enabled by describing the system configmap.
[student@workstation ~]$oc describe configmap system -n 3scale...output omitted... service_discovery.yml:----production:enabled: <%= cluster_token_file_exists = File.exists?(cluster_token_file_path = '/var/run/secrets/kubernetes.io/serviceaccount/token') %>...output omitted...
Service discovery needs the service details to create products and backends. For this, 3scale looks for the following meta data to know how to import and configure each service it finds.
Table 2.4. Service Discovery Metadata
| Type | Key | Value |
|---|---|---|
| Label | discovery.3scale.net (Required) | [true|false] to enable/disable service discovery for the service |
| Annotation | discovery.3scale.net/scheme (Required) | [http|https] scheme used by the service |
| Annotation | discovery.3scale.net/port (Required) | port number used by the service |
| Annotation | discovery.3scale.net/path | base path of the target service, if omitted the root path ("/") is used |
| Annotation | discovery.3scale.net/description-path | path to the service's OpenApi endpoint |
| Annotation | discovery.3scale.net/discovery-version | version of the 3scale discovery process |
For example, to configure a service using http and listening on port 8080 with only the required configuration:
Add the label to enable service discovery.
[student@workstation ~]$ oc label svc/SERVICE_NAME \
discovery.3scale.net="true"Add the service schema annotation:
[student@workstation ~]$ oc annotate svc/SERVICE_NAME \
discovery.3scale.net/scheme=httpAdd the service port annotation:
[student@workstation ~]$ oc annotate svc/SERVICE_NAME \
discovery.3scale.net/port="8080"You can also achieve the same result by editing the service resource definition:
[student@workstation ~]$oc edit service books-apiapiVersion: v1 kind: Service metadata: annotations:discovery.3scale.net/port: "8080"discovery.3scale.net/scheme: httpopenshift.io/generated-by: OpenShiftNewApp creationTimestamp: "2022-01-07T17:15:42Z" labels: app: books-api app.kubernetes.io/component: books-api app.kubernetes.io/instance: books-apidiscovery.3scale.net: "true"name: books-api ...output omitted...
To Discover a service located in a different project than the 3scale project, 3scale needs view permissions into the project where that service exists. To give 3scale access to other projects, the 3scale amp service account must have the view role.
[student@workstation ~]$oc policy add-role-to-user \view system:serviceaccount::amp -n3SCALE_PROJECTPROJECT_NAME
You can also give 3scale access to all the projects in the cluster by assigning it the view role as a cluster role.
[student@workstation ~]$ oc adm policy add-cluster-role-to-user view \
system:serviceaccount:3SCALE_PROJECT:ampTo make use of the discovered services, navigate to the Admin Portal to import the discovered services into 3scale products and backends.
To import a discovered service, click on the top pane drop-down menu to navigate to the Products page. Then click to navigate to the New Product form.
![]() |
In the New Product form, select . This populates the Namespace and Name drop-down menus with the discovered services. Select the desired service, then click .
By clicking , 3scale creates the product and backend based on the 3scale metadata from the service.
Although the product import creates the product and backend resources, the product is not accessible yet.
To access the imported product and the backend associated with it, the product needs a 3scale application plan and an application.
To create an application plan named APPLICATION_PLAN you must reference the TENANT and the PRODUCT_SYSTEM_NAME resources.
[student@workstation ~]$ 3scale application-plan create \
TENANT PRODUCT_SYSTEM_NAME APPLICATION_PLANTo create the application you need a user account to link it to, the PRODUCT_SYSTEM_NAME, the previously created plan, and the name you want for the application.
[student@workstation ~]$ 3scale application create \
TENANT USER_ACOUNT PRODUCT_SYSTEM_NAME APPLICATION_PLAN APPLICATIONThis application provides us with a user_key to make requests in the Staging APIcast environment.
To verify the product import, navigate to the product detail page in the Admin Portal. Then click → and scroll down to the Staging APICast section. There you can copy an example curl request to validate that your service is working properly in the staging environment.
![]() |
For more information, refer to the Service Discovery chapter in the Red Hat 3scale Api Management 2.11 Admin Portal Guide at https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.11/html/admin_portal_guide/service-discovery_service-discovery