1.24. Using the 3scale Istio adapter
The 3scale Istio Adapter is an optional adapter that allows you to label a service running within the Red Hat OpenShift Service Mesh and integrate that service with the 3scale API Management solution. It is not required for Red Hat OpenShift Service Mesh.
You can only use the 3scale Istio adapter with Red Hat OpenShift Service Mesh versions 2.0 and below. The Mixer component was deprecated in release 2.0 and removed in release 2.1. For Red Hat OpenShift Service Mesh versions 2.1.0 and later you should use the 3scale WebAssembly module.
If you want to enable 3scale backend cache with the 3scale Istio adapter, you must also enable Mixer policy and Mixer telemetry. See Deploying the Red Hat OpenShift Service Mesh control plane.
1.24.1. Integrate the 3scale adapter with Red Hat OpenShift Service Mesh 링크 복사링크가 클립보드에 복사되었습니다!
You can use these examples to configure requests to your services using the 3scale Istio Adapter.
Prerequisites
- Red Hat OpenShift Service Mesh version 2.x
- A working 3scale account (SaaS or 3scale 2.9 On-Premises)
- Enabling backend cache requires 3scale 2.9 or greater
- Red Hat OpenShift Service Mesh prerequisites
- Ensure Mixer policy enforcement is enabled. Update Mixer policy enforcement section provides instructions to check the current Mixer policy enforcement status and enable policy enforcement.
Mixer policy and telemetry must be enabled if you are using a mixer plugin.
- You will need to properly configure the Service Mesh Control Plane (SMCP) when upgrading.
To configure the 3scale Istio Adapter, refer to Red Hat OpenShift Service Mesh custom resources for instructions on adding adapter parameters to the custom resource file.
Pay particular attention to the kind: handler resource. You must update this with your 3scale account credentials. You can optionally add a service_id to a handler, but this is kept for backwards compatibility only, since it would render the handler only useful for one service in your 3scale account. If you add service_id to a handler, enabling 3scale for other services requires you to create more handlers with different service_ids.
Use a single handler per 3scale account by following the steps below:
Procedure
Create a handler for your 3scale account and specify your account credentials. Omit any service identifier.
apiVersion: "config.istio.io/v1alpha2" kind: handler metadata: name: threescale spec: adapter: threescale params: system_url: "https://<organization>-admin.3scale.net/" access_token: "<ACCESS_TOKEN>" connection: address: "threescale-istio-adapter:3333"Optionally, you can provide a
backend_urlfield within the params section to override the URL provided by the 3scale configuration. This may be useful if the adapter runs on the same cluster as the 3scale on-premise instance, and you wish to leverage the internal cluster DNS.Edit or patch the Deployment resource of any services belonging to your 3scale account as follows:
-
Add the
"service-mesh.3scale.net/service-id"label with a value corresponding to a validservice_id. -
Add the
"service-mesh.3scale.net/credentials"label with its value being the name of the handler resource from step 1.
-
Add the
- Do step 2 to link it to your 3scale account credentials and to its service identifier, whenever you intend to add more services.
Modify the rule configuration with your 3scale configuration to dispatch the rule to the threescale handler.
Rule configuration example
apiVersion: "config.istio.io/v1alpha2" kind: rule metadata: name: threescale spec: match: destination.labels["service-mesh.3scale.net"] == "true" actions: - handler: threescale.handler instances: - threescale-authorization.instance
1.24.1.1. Generating 3scale custom resources 링크 복사링크가 클립보드에 복사되었습니다!
The adapter includes a tool that allows you to generate the handler, instance, and rule custom resources.
| Option | Description | Required | Default value |
|---|---|---|---|
|
| Produces help output for available options | No | |
|
| Unique name for this URL, token pair | Yes | |
|
| Namespace to generate templates | No | istio-system |
|
| 3scale access token | Yes | |
|
| 3scale Admin Portal URL | Yes | |
|
| 3scale backend URL. If set, it overrides the value that is read from system configuration | No | |
|
| 3scale API/Service ID | No | |
|
| 3scale authentication pattern to specify (1=API Key, 2=App Id/App Key, 3=OIDC) | No | Hybrid |
|
| File to save produced manifests to | No | Standard output |
|
| Outputs the CLI version and exits immediately | No |
1.24.1.1.1. Generate templates from URL examples 링크 복사링크가 클립보드에 복사되었습니다!
-
Run the following commands via
oc execfrom the 3scale adapter container image in Generating manifests from a deployed adapter. -
Use the
3scale-config-gencommand to help avoid YAML syntax and indentation errors. -
You can omit the
--serviceif you use the annotations. -
This command must be invoked from within the container image via
oc exec.
Procedure
Use the
3scale-config-gencommand to autogenerate templates files allowing the token, URL pair to be shared by multiple services as a single handler:$ 3scale-config-gen --name=admin-credentials --url="https://<organization>-admin.3scale.net:443" --token="[redacted]"The following example generates the templates with the service ID embedded in the handler:
$ 3scale-config-gen --url="https://<organization>-admin.3scale.net" --name="my-unique-id" --service="123456789" --token="[redacted]"
1.24.1.2. Generating manifests from a deployed adapter 링크 복사링크가 클립보드에 복사되었습니다!
-
NAMEis an identifier you use to identify with the service you are managing with 3scale. -
The
CREDENTIALS_NAMEreference is an identifier that corresponds to thematchsection in the rule configuration. This is automatically set to theNAMEidentifier if you are using the CLI tool. - Its value does not need to be anything specific: the label value should just match the contents of the rule. See Routing service traffic through the adapter for more information.
Run this command to generate manifests from a deployed adapter in the
istio-systemnamespace:$ export NS="istio-system" URL="https://replaceme-admin.3scale.net:443" NAME="name" TOKEN="token" oc exec -n ${NS} $(oc get po -n ${NS} -o jsonpath='{.items[?(@.metadata.labels.app=="3scale-istio-adapter")].metadata.name}') \ -it -- ./3scale-config-gen \ --url ${URL} --name ${NAME} --token ${TOKEN} -n ${NS}-
This will produce sample output to the terminal. Edit these samples if required and create the objects using the
oc createcommand. When the request reaches the adapter, the adapter needs to know how the service maps to an API on 3scale. You can provide this information in two ways:
- Label the workload (recommended)
-
Hard code the handler as
service_id
Update the workload with the required annotations:
참고You only need to update the service ID provided in this example if it is not already embedded in the handler. The setting in the handler takes precedence.
$ export CREDENTIALS_NAME="replace-me" export SERVICE_ID="replace-me" export DEPLOYMENT="replace-me" patch="$(oc get deployment "${DEPLOYMENT}" patch="$(oc get deployment "${DEPLOYMENT}" --template='{"spec":{"template":{"metadata":{"labels":{ {{ range $k,$v := .spec.template.metadata.labels }}"{{ $k }}":"{{ $v }}",{{ end }}"service-mesh.3scale.net/service-id":"'"${SERVICE_ID}"'","service-mesh.3scale.net/credentials":"'"${CREDENTIALS_NAME}"'"}}}}}' )" oc patch deployment "${DEPLOYMENT}" --patch ''"${patch}"''
1.24.1.3. Routing service traffic through the adapter 링크 복사링크가 클립보드에 복사되었습니다!
Follow these steps to drive traffic for your service through the 3scale adapter.
Prerequisites
- Credentials and service ID from your 3scale administrator.
Procedure
-
Match the rule
destination.labels["service-mesh.3scale.net/credentials"] == "threescale"that you previously created in the configuration, in thekind: ruleresource. -
Add the above label to
PodTemplateSpecon the Deployment of the target workload to integrate a service. the value,threescale, refers to the name of the generated handler. This handler stores the access token required to call 3scale. -
Add the
destination.labels["service-mesh.3scale.net/service-id"] == "replace-me"label to the workload to pass the service ID to the adapter via the instance at request time.