Skip to content

Deploying & Invoking a managed API on WSO2 Kubernetes Gateway With Control Plane

This section is a step-by-step guide to creating, deploying, and invoking an API using the WSO2 Kubernetes Gateway with APIM Control Plane. It including creating an API from the UI.

Note

To set up the Kubernetes Gateway as an enterprise version, please follow the steps specified in both the Install Kubernetes Gateway Enterprise and Install Kubernetes Gateway Agent Enterprise.

Before you begin...

Install the prerequisites that are required to run the WSO2 API Platform for Kubernetes.

Note

If you already have an installation of the Kubernetes Gateway in your cluster, please remove the installation by following the steps specified in the Uninstall Kubernetes Gateway section.

Create Kubernetes namespace

kubectl create ns apk

Configure the hosts file

Add a hostname mapping to the /etc/hosts file as follows.

IP Domain name
127.0.0.1 api.am.wso2.com
127.0.0.1 am.wso2.com
127.0.0.1 idp.am.wso2.com
127.0.0.1 default.gw.wso2.com

Step 1 - Setup APIM Control Plane with Kubernetes Gateway

There are 3 components which you need to setup to get the Kubernetes Gateway working with APIM. They are,

Setup WSO2 API Manager Control Plane 4.5.0

Setup WSO2 API Manager 4.5.0 in K8s cluster using Helm Charts.

Note

The Quick Start Guide (QSG) uses an in-memory H2 database for the API Manager Control Plane. Restarting the APIM pod will erase all existing data. To enable persistent storage, configure APIM to use a production-grade database such as MySQL. For step-by-step instructions, see the Deploy APIM with DB guide.

  1. Create a new helm repository with the latest apim release using the following command. Let’s consider the <repository-name> as wso2apim.

    helm repo add wso2apim https://github.com/wso2/helm-apim/releases/download/acp-4.5.0
    
  2. Execute the following command to update the helm repositories.

    helm repo update
    
  3. Consider apim as the <chart-name> for this guide. As the --version of this command, use the version of the release you used in point 1 above. It will take a few minutes for the deployment to complete.

    helm install apim wso2apim/wso2am-acp --version 4.5.0-1 -f https://raw.githubusercontent.com/wso2/apk/main/helm-charts/samples/apim/cp/4.5.0-values.yaml -n apk
    
    helm install <chart-name> <repository-name>/wso2am-acp --version <version-of-APIM> -f <path-to-values.yaml-file>
    
  4. Install NGINX Ingress Controller. Please refer to the NGINX Ingress Controller documentation for more information.

Note

Please refer to the Advanced Configuration for APIM for more information.

Setup WSO2 Kubernetes Gateway 1.3.0

  1. Create a new helm repository with the latest kubernetes gateway release using the following command. Let’s consider the <repository-name> as wso2apk.

    helm repo add wso2apk https://github.com/wso2/apk/releases/download/1.3.0
    
  2. Execute the following command to update the helm repositories.

    helm repo update
    
  3. Install the Kubernetes Gateway components and start WSO2 API Platform For Kubernetes. Consider apk as the <chart-name> for this guide. As the --version of this command, use the version of the release you used in point 1 above. It will take a few minutes for the deployment to complete.

Note

If you already have an installation of the Kubernetes Gateway in your cluster, please remove the installation by following the steps specified in the Uninstall Kubernetes Gateway section.

helm install apk wso2apk/apk-helm --version 1.3.0 -f https://raw.githubusercontent.com/wso2/apk/main/helm-charts/samples/apk/1.3.0-cp-enabled-values.yaml -n apk
helm install <chart-name> <repository-name>/apk-helm --version <version-of-APK> -f <path-to-values.yaml-file>

Note

Please refer to the Advanced Configuration for APK for more information.

Setup WSO2 Kubernetes Gateway Agent 1.3.0

  1. Create a new helm repository with the latest kubernetes gateway agent release using the following command. Let’s consider the <repository-name> as wso2apkagent for this guide.

    helm repo add wso2apkagent https://github.com/wso2/product-apim-tooling/releases/download/1.3.0
    
  2. Execute the following command to update the helm repositories.

    helm repo update
    
  3. Install the Kubernetes Gateway Agent components and start WSO2 API Platform For Kubernetes. Consider apk as the <chart-name> for this guide. As the --version of this command, use the version of the release you used in point 1 above. It will take a few minutes for the deployment to complete.

    helm install apim-apk-agent wso2apkagent/apim-apk-agent --version 1.3.0 -f https://raw.githubusercontent.com/wso2/apk/main/helm-charts/samples/apim-apk-agent/1.3.0-values.yaml -n apk
    
    helm install <chart-name> <repository-name>/apim-apk-agent --version <version-of-APK-Agent> -f <path-to-values.yaml-file>
    

Note

Please refer to the Advanced Configuration for Agent for more information.

Verify the deployment

Now you can verify the deployment by executing the following command. You will see the status of the pods as follows once completed.

kubectl get pods -n apk

Step 2 - Create and Deploy the API

Create Deploy and Publish the API

  1. Login to the Publisher Console (https://am.wso2.com/publisher) of the WSO2 API Manager.
  2. Click on the REST API button and then use Import Open API option.
  3. Provide the OpenAPI definition of the API and click Next. Select OpenAPI URL and provide the below link as the URL. Click Next.
    https://raw.githubusercontent.com/wso2/docs-apk/refs/heads/1.3.0/en/docs/assets/files/get-started/SampleAPIDefinition.json
    
  4. Edit the information as given below and click Create.
Field Sample value
Name SampleService
Context /sample-api
Version 0.1.0
Endpoint https://dev-tools.wso2.com/gs/helpers/v1.0
  1. Navigate to the Deploy section and click Deployments.
  2. Click Deploy New Revision.
  3. Optionally, provide a description for the revision.
  4. Select the Kubernetes Gateways in which you want to deploy the API and click Deploy.
  5. Navigate to Life Cycle tab. Then click Publish to publish the API.
  6. To verify the API deployment in the Kubernetes Gateway, execute the following command. You will see the status of the deployed apis as follows once completed.
   kubectl get apis -n apk

Create Application and Subscribe to the API

  1. Login to the Developer Portal (https://am.wso2.com/devportal) of the WSO2 API Manager.
  2. Click on the Applications tab and then use ADD NEW APPLICATION option.
  3. Provide the information as given below and click Save.

    FieldValue
    Application NameSampleServiceApp
    Per Token Quota10PerMin
    DescriptionSample Service Application

  4. Click Subscriptions to subscribe to the created SampleService API.

  5. Click Production Keys or Sandbox Keys based on the environment for which you need to generate keys. Let's assume that you are working in a production environment. Therefore, click Production Keys.
  6. Click Generate Keys to create an application Access Token with relevant scopes.
  7. To verify the Application and Subscription creation in the kubernetes gateway, execute the following command. You will see the status of the deployed application as follows once completed.

    kubectl get subscriptions -n apk
    kubectl get applications -n apk
    

Important

The database storage option is offered in APK for deployments with a high number of subscriptions and applications, especially for enterprise use cases. Because, by default, subscription and application-related data are stored as CRs (Custom Resources) in etcd. However, as the number of subscriptions and applications increases, it can lead to overutilization of etcd memory, subsequently degrading the performance of your API gateway. This degradation can impact the deployment, un-deployment, and update times ultimately affecting the reliability of applications and subscriptions.

By opting for the database option offered in APK for deployments with high numbers of subscriptions and applications, you can mitigate issues related to etcd storage, such as memory overutilization and performance degradation. This ensures smoother deployment, undeployment, and update processes, ultimately enhancing the reliability of your applications and subscriptions. For further information and assistance, please contact our sales team https://wso2.com/contact/?ref=consulting.

Step 3 - Invoke the API

Use the following command to invoke the API using the access token generated in the previous step.

    curl -X GET "https://default.gw.wso2.com:9095/sample-api/0.1.0/uuid" -H "Authorization: Bearer <access-token>" -k