This sample demonstrates how to build and deploy an ASP.NET Core-based microservice as an extension leveraging the minimal web API functionality and exposing the API in SAP BTP, Kyma runtime.
You can find the application code in the TodoApi directory.
This sample demonstrates how to:
- Create a development Namespace in the Kyma runtime.
- Create and deploy an ASP.NET Core-based application in the Kyma runtime.
- Expose the ASP.NET Core application using APIRules.
- Call the API.
The application used in this sample is described here
This tutorial requires the following prerequisites:
- Create a new
dotnetdev
Namespace:
kubectl create namespace dotnetdev
kubectl label namespaces dotnetdev istio-injection=enabled
- Adjust the placeholder
DOCKER_ACCOUNT
in the Makefile and then build and push the image to the Docker repository:
DOCKER_ACCOUNT={your-docker-account} make build-and-push-image
- Update the image name in the Kubernetes Deployment. Refer to the standard Kubernetes Deployment and Service definitions.
This section details out deploying the extension using standard Kubernetes resources.
To deploy as Helm chart, please refer to Helm Chart Deployment
- Deploy the application:
kubectl -n dotnetdev apply -f ./k8s/deployment.yaml
- Verify that the Pods are up and running:
kubectl -n dotnetdev get po -l app=sample-extension-dotnet-minimalapi
The expected result shows that the Pod for the sample-extension-dotnet
Deployment is running:
kubectl -n dotnetdev get po -l app=sample-extension-dotnet-minimalapi
NAME READY STATUS RESTARTS AGE
sample-extension-dotnet-minimalapi-774fbc5c7b-x44pd 2/2 Running 0 15s
- 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-dotnet-minimalapi
spec:
gateway: kyma-gateway.kyma-system.svc.cluster.local
rules:
- accessStrategies:
- config: {}
handler: noop
methods:
- GET
- POST
- PUT
- DELETE
path: /.*
service:
host: sample-extension-dotnet-minimalapi
name: sample-extension-dotnet-minimalapi
port: 5046
This sample snippet exposes the sample-extension-dotnet-minimalapi
Service. The Service is specified in the spec.service.name field.
The sample-extension-dotnet-minimalapi
subdomain is specified in the spec.service.host field.
- Apply the APIRule:
kubectl -n dotnetdev apply -f ./k8s/api-rule.yaml
A Helm Chart definition is also available for developers to try out.
The following prerequisites are needed:
To install the helm chart in dotnetdev
namespace, run the following command. Change the placeholder <YOUR DOCKER ACCOUNT>
to use your account.
helm install kymaapp ../helm-charts/sample-extension-dotnet-minimalapi --set image.repository=<YOUR DOCKER ACCOUNT>/dotnet6minimalapi:0.0.1 -n dotnetdev
To verify, the installed chart, run
helm -n dotnetdev ls
This should give you an output like
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
dev-gateway dev 1 2020-09-14 17:34:58.607853163 +0000 UTC deployed gateway-0.0.1
kymaapp dev 1 2020-09-15 15:18:34.502591 +0200 CEST deployed sample-extension-dotnet-0.1.0 1.16.0
Access the APIs through this URL:
https://sample-extension-dotnet-minimalapi.{cluster domain}
See several sample calls in the file samplerequests.http. Put the right name for the hostname into the file and execute the different commands to interact with your todo list.