Skip to content

Latest commit

 

History

History
133 lines (90 loc) · 3.99 KB

File metadata and controls

133 lines (90 loc) · 3.99 KB

Micronaut based extension with API exposed via Microgateway

Overview

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.

extension

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.

Prerequisites

Application

The Micronaut application implements a simple Orders API with CRUD operations.

Steps

Prepare for deployment

  • 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

Kubernetes Deployment

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:

Expose the API

  • 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

Helm Chart Deployment

A Helm Chart definition is also available for developers to try out.

Must Haves

Helm install

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

Try it out

Access the APIs through this URL: <https://sample-extension-micronaut.{cluster domain}/orders>

Try out various APIs.