This sample demonstrates how to build and deploy a Java-based microservice as an extension and expose the API in SAP BTP, Kyma runtime.
This sample demonstrates how to:
- Create a development Namespace in the Kyma runtime.
- Create and deploy a Spring Boot application in the Kyma runtime.
- Expose the Spring Boot application using APIRules.
- Explore the APIs.
- SAP BTP, Kyma runtime instance
- Kubernetes tooling
- Docker
- make
- Gradle
- Pack if building images using buildpacks
The Spring Boot 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 the image
-
Using Dockerfile
DOCKER_ACCOUNT={your-docker-account} make build-image-using-docker
-
or, alternatively Using Buildpacks
DOCKER_ACCOUNT={your-docker-account} make build-image-using-pack
-
-
Push the image
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-java
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-java spec: gateway: kyma-gateway.kyma-system.svc.cluster.local rules: - accessStrategies: - config: {} handler: noop methods: - GET - POST - PUT - DELETE path: /.* service: host: sample-extension-java name: sample-extension-java port: 8080
This sample snippet exposes the
sample-extension-java
Service. The Service is specified in the spec.service.name field. Thesample-extension-java
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-java --set image.repository=gabbi/sample-extension-java: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-java.{cluster domain}/orders>
Try out various APIs.