This sample demonstrates how to build and deploy a Micronaut microservice as an extension and expose the API in SAP BTP, Kyma runtime.
Micronaut enables creating native images using GraalVM for Java.
This sample demonstrates how to:
- Create a development Namespace in the Kyma runtime.
- Create and deploy a Micronaut application in the Kyma runtime.
- Expose the application using APIRules.
- Explore the APIs.
- SAP BTP, Kyma runtime instance
- Docker
- make
- Gradle
- kubectl configured to use the
KUBECONFIG
file downloaded from the Kyma runtime - Java 8+
The Micronaut application implements a simple Orders
API with CRUD operations.
-
Create a new
dev
Namespace:kubectl create namespace dev kubectl label namespaces dev istio-injection=enabled
-
Build and push the image to the Docker repository:
DOCKER_ACCOUNT={your-docker-account} make push-image
This section details out deploying the extension using standard Kubernetes resources.
To deploy as Helm chart, please refer to Helm Chart Deployment
-
Update the image name in the Kubernetes Deployment. Refer to the standard Kubernetes Deployment and Service definitions.
-
Deploy the application:
kubectl -n dev apply -f ./k8s/deployment.yaml
-
Verify that the Pods are up and running:
kubectl -n dev get po
The expected result shows that the Pod for the sample-extension-micronaut
Deployment is running:
-
Create an APIRule. In the APIRule, specify the Kubernetes Service that is exposed:
apiVersion: gateway.kyma-project.io/v1alpha1 kind: APIRule metadata: name: sample-extension-micronaut spec: gateway: kyma-gateway.kyma-system.svc.cluster.local rules: - accessStrategies: - config: {} handler: noop methods: - GET - POST - PUT - DELETE path: /.* service: host: sample-extension-micronaut name: sample-extension-micronaut port: 8080
This sample snippet exposes the sample-extension-micronaut
Service. The Service is specified in the spec.service.name field.
The sample-extension-micronaut
subdomain is specified in the spec.service.host field.
-
Apply the APIRule:
kubectl -n dev apply -f ./k8s/api-rule.yaml
A Helm Chart definition is also available for developers to try out.
To install the helm chart in dev
namespace, run the following command. Change to use your image. You can also override other parameters defined in values.yaml
helm -n dev install kymaapp ../helm-charts/sample-extension-micronaut --set image.repository=gabbi/sample-extension-micronaut:0.0.7 --set jdbc.user={db user} --set jdbc.password={db password}
To verify, the installed chart, run
helm -n dev ls
Access the APIs through this URL: <https://sample-extension-micronaut.{cluster domain}/orders>
Try out various APIs.