This section describes how to test Gravitee Kubernetes Operator (GKO) functionality after deployment. The process involves the following stages:
- Create a
ManagementContext
custom resource - Create an
ApiDefinition
custom resource, which creates a new API on the cluster - Test the new API by calling it through the APIM Gateway
- Ensure that the GKO has been successfully deployed on your Kubernetes cluster.
- Ensure that
services.sync.kubernetes
is set totrue
. This property is disabled by default, but must be enabled for the Gateway to communicate with a Kubernetes Operator. How the Gateway is deployed determines how the property is configured:- If your Gateway is deployed using a Helm Chart, you can enable the Kubernetes Operator option through helm values.
- For other deployment strategies (e.g., deployment using a VM), you can update the configuration:
- By setting an environment variable:
GRAVITEE_SERVICES_SYNC_KUBERNETES_ENABLED=true
- Directly in the
gravitee.yml
file:
- By setting an environment variable:
{% code title="gravitee.yml" %}
# Enable Kubernetes Synchronization
# This sync service requires to install Gravitee Kubernetes Operator
# kubernetes:
# enabled: false
{% endcode %}
{% hint style="info" %} See the Configure APIM Gateway section for more information on using environment variables in Gateway configurations. {% endhint %}
To create a ManagementContext
custom resource for your APIM instance requires a YAML file with the correct Management Context configuration. The following sample Gravitee YAML file can be used directly or as a template:
{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-kubernetes-operator/blob/master/config/samples/context/k3d/management-context-with-credentials.yml" %}
To create the Management Context resource using the Gravitee sample file directly, modify the spec:
section by providing the actual URL of your APIM instance and the user credentials that match the relevant user configuration. Next, run the following command:
{% code overflow="wrap" %}
kubectl apply -f https://raw.githubusercontent.com/gravitee-io/gravitee-kubernetes-operator/master/config/samples/context/k3d/management-context-with-credentials.yml
{% endcode %}
Alternatively, to create the Management Context resource using a modified configuration, run the following command (using the appropriate filename):
kubectl apply -f your_management_context_credentials_config.yaml
If the operation is successful, you should see this line in the command-line output:
managementcontext.gravitee.io/dev-mgmt-ctx created
{% hint style="success" %} The Management Context resource has now been created. {% endhint %}
To create an ApiDefinition
custom resource requires a YAML file with the desired API Definition configuration. The following sample Gravitee YAML file can be used directly or as a template:
{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-kubernetes-operator/blob/master/config/samples/apim/api-with-context.yml" %}
To create the API Definition resource using the Gravitee sample file directly, run the following command:
{% code overflow="wrap" %}
kubectl apply -f https://raw.githubusercontent.com/gravitee-io/gravitee-kubernetes-operator/master/config/samples/apim/api-with-context.yml
{% endcode %}
Alternatively, to create the API Definition resource using a modified configuration, run the following command (using the appropriate filename):
kubectl apply -f your_api_definition_config.yml
If the operation is successful, you should see this line in the command-line output:
apidefinition.gravitee.io/basic-api-example created
{% hint style="success" %} The API Definition resource has now been created and a new API has been added to your Console. {% endhint %}
View the new API at your Console URL:
http://<YOUR_CONSOLE_URL>/console/#!/environments/default/
If you are using a local cluster created through the local cluster installation process, the Console URL will likely be as follows:
http://localhost:9000/console/#!/environments/default/
The new API will be listed in the "Number of APIs" section of the Console dashboard:
APIM Console dashboard
To test the API, you can call it through the APIM Gateway with the following command (after updating the placeholder to use your APIM Gateway URL):
curl -i http://<YOUR_GATEWAY_URL>/gateway/k8s-basic-with-ctx
If you are using a local cluster created through the local cluster installation process, the Gateway URL is likely http://localhost:9000/gateway/k8s-basic-with-ctx
. However, the entrypoint used for the Gateway URL may differ depending on your deployment.