Follow the instructions below to deploy WSO2 API Microgateway in Kubernetes.
Step 1 - Follow the installation prerequisites
Make sure to do the following:
- Carry out the installation prerequisites for WSO2 API Microgateway Toolkit.
- Install and setup kubectl in your client machine.
- Setup a Kubernetes cluster.
- Make sure that kubectl points to your Kubernetes cluster.
Step 2 - Create a Microgateway project
- Navigate to a preferred workspace folder using the command line to set the location that is used to store the Microgateway project.
Create a project.
Let's create a project named
k8s_projectby running the following command. This will create the folder structure for the artifacts to be included.
Step 3 - Build the Microgateway project
Add the API to the project.
Navigate to the
/petstore/api_definitionsdirectory and add the OpenAPI definition(s) to this directory. Let's use the Petstore sample OpenAPI definition in this scenario.
Create the input for WSO2 API Microgateway Toolkit.
deployment.tomlfile that you will use as the input when creating the microgateway project. This TOML file should contain the relevant deployment configurations as shown below. For more information on each of the above parameters, see deployment.toml for Kubernetes.
Make sure to specify the complete path for the
ballerinaConf, by replacing the
<MICROGW_TOOLKIT_HOME>placeholder with the full path.
Build the microgateway project.
Use your command line tool to navigate to where the project directory (
k8s_project) was created and execute the following command to build the project.
This generates the following Kubernetes resources.
│ └── docker
│ └── Dockerfile
The Docker image to be deployed in Kubernetes is created in your local registry. You can find the image
k8s_project:latestwhen you execute the Docker images command.
Step 4 - Deploy the Docker image in a Kubernetes environmentLet's SCP the image to the Kubernetes nodes to deploy the Docker image in a K8s environment.
For more options on deploying the Docker image in a Kubernetes environment, see the Deployment related FAQs.
Save the Docker image to a
SCP the image to the Kubernetes nodes.
Identity file- This refers to the public key of the Kubernetes node. For example you can get a google_compute_engine.pub for GCE. You have to
scpthe Docker image for each and every Kubernetes node.
When using minikube, the username is
dockerand you can find the IP address by using the
Load the Docker image in the Kubernetes nodes.
You need to execute the following command in the Kubernetes nodes.
Step 5 - Start the Kubernetes cluster
Deploy WSO2 API Microgateway in Kubernetes by deploying the Kubernetes resources (artifacts) and starting WSO2 API Microgateway.
Step 6 - Invoke the sample API
Step 6.1 - Obtain token
After the APIs are exposed via WSO2 API Microgateway, which you deployed in a Kubernetes cluster, you can invoke an API with a valid JWT token or an opaque access token.
In order to use JWT tokens, WSO2 API Microgateway should be presented with a JWT signed by a trusted OAuth2 service.
Let's use the following sample JWT token that never expires, which was generated using WSO2 API Manager for testing purposes.
Step 6.2 - Invoke the API
Invoke the API using the JWT token using the following command.
Execute the command below to set a self-contained OAuth2.0 access token in the JWT format as a variable on your terminal session.
When you are deploying the Microgateway in production, make sure to change its default certificates.
You can now invoke the API running on the Microgateway using the following cURL command.
As this example uses
NodePortas the service typein Kubernetes, you can access the API using any of the Kubernetes node IP addresses and node ports when using the latter mentioned service type.
In addition, you can use the
kubectl get svccommand to list down the services that run on Kubernetes in order to get the port. However, to identify an external IP of the Kubernetes cluster you can use the command
kubectl get nodes -o yaml | grep -B 1 "type: ExternalIP"
If you use minukube as the Kuberneterse cluster, then you can find the external IP by using the
In the above example, localhost is used as the Kubernetes node IP, because it was based on Kubenetes that was provided by Docker for Mac.