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
dotnetdevNamespace:
kubectl create namespace dotnetdev
kubectl label namespaces dotnetdev istio-injection=enabled- Adjust the placeholder
DOCKER_ACCOUNTin 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-minimalapiThe 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/v2
kind: APIRule
metadata:
name: sample-extension-dotnet-minimalapi
spec:
gateway: kyma-system/kyma-gateway
hosts:
- sample-extension-dotnet-minimalapi
rules:
- noAuth: true
methods:
- GET
- POST
- PUT
- DELETE
path: /*
service:
name: sample-extension-dotnet-minimalapi
port: 5046This 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.yamlA 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 dotnetdevTo verify, the installed chart, run
helm -n dotnetdev lsThis 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.0Access 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.