Managing APIs in Kubernetes

WSO2 API Controller (apictl) allows you to manage APIs in Kubernetes with the use of WSO2 API Operator. This approach uses the Kubernetes native way to deploy the APIs into a running Microgateway cluster from the command line.

Prerequisites

Info

Before you begin

Add an API to Kubernetes cluster

  1. Run the following command to add an API to the Kubernetes cluster using either a swagger file, zip file, or an API project folder. When you add the API to the Kubernetes cluster, the API operator successfully deploys the project zip to the WSO2 microgateway Adapter component.

    • Command

      apictl k8s add api -n <API Name> -f <Location of the swagger file, zip file or API project folder>

      Info

      Flags:

      • Required :
        --name or -n : Name of the API --file or -f : Location of the swagger file, zip file or the API project folder

      Example

      apictl k8s add api -n PizzaShackAPI -f swagger.yaml
      apictl k8s add api -n PizzaShackAPI -f PizzaShackAPI_1.0.0.zip
      apictl k8s add api -n PizzaShackAPI -f PizzaShackAPI-1.0.0

    • Response

      creating configmap with swagger definition            
      configmap/pizzashackapi-swagger created                                             
      creating API definition                                                  
      api.wso2.com/pizzashackapi created

Update an API in Kubernetes cluster

  1. Run the following command to update an API in the Kubernetes cluster using either a swagger file, zip file, or an API project folder. When you update the API in the Kubernetes cluster, the API operator successfully deploys the updated project zip to the WSO2 microgateway Adapter component.

    • Command

      apictl k8s update api -n <API Name> -f <Location of the swagger file, zip file or API project folder>

      Info

      Flags:

      • Required :
        --name or -n : Name of the API --file or -f : Location of the swagger file, zip file or the API project folder

      Example

      apictl k8s update api -n PizzaShackAPI -f swagger.yaml
      apictl k8s update api -n PizzaShackAPI -f PizzaShackAPI_1.0.0.zip
      apictl k8s update api -n PizzaShackAPI -f PizzaShackAPI-1.0.0

    • Response

      creating configmap with swagger definition
      configmap/pizzashackapi-swagger-1614042541 created
      creating API definition
      api.wso2.com/pizzashackapi configured
      configmap "pizzashackapi-swagger" deleted

Delete an API in Kubernetes cluster

  1. Run the following command to delete an API in the Kubernetes cluster.

    • Command

      apictl k8s delete api -n <API Name>

      Info

      Flags:

      • Required :
        --name or -n : Name of the API

      Example

      apictl k8s delete api -n PizzaShackAPI
    • Response

      api.wso2.com "pizzashackapi" deleted

Generate Deployment Directory for Kubernetes

  1. Run the following command to generate a sample directory with all the contents to use as the deployment directory when performing CI/CD pipeline tasks in Kubernetes.

    • Command

      apictl k8s gen deployment-dir -s <Path of Source directory> -d <Path of Destination directory>

      Info

      Flags:

      • Required :
        --source or -s : Path of the source directory to be used when generating the directory. Source can be a API project folder or a zipped API project.
      • Optional : --destination or -d : Path of the destination directory where the directory should be generated.

      Example

       apictl k8s gen deployment-dir -s PizzaShackAPI-1.0.0
       apictl k8s gen deployment-dir -s PizzaShackAPI-1.0.0 -d Deployment-Directory

    • Response

      The deployment directory for PizzaShackAPI-1.0.0 file is generated at Deployment-Directory

    A project folder with the following default structure will be created in the given directory.

    <API_Name>-<API_Version>
    ├── api_crd.yaml
    ├── api_meta.yaml (api_product_meta.yaml for API Products)
    ├── certificates
    └── <API_Name>-params.yaml   

    Sub Directory/File Description
    API_Name-params.yaml The config map of params.yaml which is the specification of the environment specific configurations.
    api_meta.yaml/api_product_meta.yaml The meta-information file of the source artifact (This includes the name and the version of the source).
    certificates Contains the client certificates for Mutual SSL enabled APIs/API Products and endpoint certificates for endpoint security enabled APIs.
    api_crd.yaml The Custom Resource Definition of the API.

  2. You can add kustomization.yaml, kustomize-config.yaml and project zip file (Eg: PizzaShackAPI_1.0.0.zip).

  3. Run the following command to generate the related config maps.

    • Command

      kubectl kustomize
      
Top