Contact Free trial Login

Bind Your Service to an API Using the CLI

When you create the binding, Anypoint Service Mesh creates a three-way association of the service in Kubernetes, the API that you created in Anypoint Platform to represent the service, and the adapter that you created for the service. The adapter uses the unique API ID to fetch policies and apply them to your services that are running in the cluster.

If you created the API using Anypoint Platform, you use the API ID to bind the service. However, if you you used Anypoint Service Mesh to create the API, you must use the Kubernetes API resource name to bind the service.

After the binding is created, Anypoint Service Mesh takes a few seconds to complete the binding procedure and update the status. After the binding is completed, you can view the status using the list command. The status values include:

  • Ready: The binding is now ready to be used.

  • Failed: The binding was not created successfully. An error occurred.

  • Binding: The binding is in the process of being associated with specific application.

In the following example, a binding called customers is created to bind the anypoint-service-mesh-adapter adapter with the customers service. This binding is created in the nto-payments namespace, which is the same namespace where the adapter was previously created, and is associated with the API that has the ID as 1234.

NAMESPACE      NAME        ADAPTER                         API ID  SERVICE NAME    STATUS
nto-payments   customers   anypoint-service-mesh-adapter   1234    customers       Ready

Methods for Binding an API

You can bind an API to a service using Anypoint Platform or Anypoint Service Mesh, based on your preference:

Bind an API Created Using Anypoint Platform

Before you bind the service, from the API Administration Tab of API Manager, obtain the API ID.

To bind the service with an API, perform the following steps:

  1. Go to Anypoint Platform > API administration and expand the API version name to display the instances.

  2. Click an instance name.

  3. From the API instance window, save the API ID to a text editor:

    Display API ID
    Figure 1. The diagram shows the location where the API ID is displayed on the API version window.
    1 API name and API instance version.
    2 API ID.
  4. Retrieve from Kubernetes the name of the service with which you want to bind the API:

    kubectl get svc -n namespace

  5. Verify that your microservice port is named according to the requirements described in Istio.

  6. From the Anypoint Service Mesh installer download location in the Command window, bind the adapter with an application:

    asmctl adapter binding create \
    --name=_Kubernetes binding resource name_ \
    --namespace=_namespace name_ \
    --adapter=_Kubernetes adapter resource name_ \
    --apiId=_api ID_ \
    --serviceName=_service name_

    Note that all object names, such as adapter name, binding name, and service name, must be in lowercase letters. An error is thrown if you do not follow Kubernetes naming conventions.

    Parameter Name Description Required or Optional Default Value

    name

    The unique name that represents the Kubernetes binding resource, for example, service-binding-anypoint-security.

    Required

    Not applicable

    namespace

    The namespace in which your service is deployed. Ensure that you use the same namespace as the adapter you provisioned earlier.

    Required

    Not applicable

    adapter

    Specify the name of the Kubernetes adapter resource that you provisioned earlier.

    Required

    Not applicable

    apiId

    Specify the API ID of the API that you acquired prior to beginning this procedure.

    Required

    Not applicable

    serviceName

    The name of the service that you want to bind to the API. The service name is the identifier of the service that you want to manage with Anypoint Service Mesh.

    Required

    Not applicable

    The binding is activated within a few seconds and the API is successfully registered to the proxy.

  7. Verify the binding status:

    asmctl adapter binding list

    After you bind your API, the API in API Manager is marked as Active. You are now ready to apply policies to protect your APIs:

    75%
    Figure 2. The diagram shows the location where the status of the service is displayed.
    1 API name and API instance version.
    2 Service status.

Bind an API Created Using Anypoint Service Mesh

To create the binding:

  1. Retrieve from Kubernetes the name of the service with which you want to bind the API:

    kubectl get svc -n namespace

  2. Verify that your microservice port is named based on Istio requirements.

  3. From the Anypoint Service Mesh installer download location, bind the adapter with an API:

    asmctl api binding create \
    --name=_Kubernetes resource name_ \
    --namespace=_namespace name_ \
    --adapter=_Kubernetes adapter resource_ \
    --api=_Kubernetes API resource_ \
    --serviceName=_service name_
    Parameter Name Description Required or Optional Default Value

    name

    The unique name that represents the Kubernetes binding resource, for example, service-binding-anypoint-security.

    Required

    Not applicable

    namespace

    The namespace in which your service is deployed. Ensure that you use the same namespace as the adapter you provisioned earlier.

    Required

    Not applicable

    adapter

    Specify the Kubernetes adapter resource that you provisioned earlier.

    Required

    Not applicable

    api

    Specify the Kubernetes API resource that you want to associate with this adapter.

    Required

    Not applicable

    serviceName

    The name of the service that you want to bind to the API. The service name is the identifier of the service that you want to manage with Anypoint Service Mesh.

    Required

    Not applicable

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub