|
| 1 | +# Orders Service |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This example demonstrates how you can use Kyma to expose microservices and Functions on HTTP endpoints and bind them to an external database. |
| 6 | + |
| 7 | +This example contains: |
| 8 | + |
| 9 | +- A sample application (microservice) written in [Go](http://golang.org). It can expose HTTP endpoints used to create, read, and delete basic order JSON entities, as described in the [service's OpenAPI specification](docs/openapi.yaml). This service can run with either a default in-memory database or the external Redis database. |
| 10 | + |
| 11 | +- A [serverless](https://kyma-project.io/#/01-overview/serverless/README) Function with the ability to expose HTTP endpoints used to read all order records or post single orders. Just like the microservice, the Function can run with either the default in-memory database or the external Redis instance. See the source code of this Function in the [`function.yaml`](./deployment/orders-function.yaml)) file under the **spec.source** field. |
| 12 | + |
| 13 | +To see this microservice and Function in action, see the [getting started guides](https://github.com/kyma-project/kyma/blob/release-1.24/docs/getting-started/01-overview.md) and learn more about exposing services and Functions through API Rule CRs. You will also learn how to bind them to an external application like Redis and subscribe them to events from a sample mock application. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- Kyma 1.14 or higher. To deploy the Function, [Serverless](https://github.com/kyma-project/kyma/tree/release-1.24/docs/serverless) must be installed on the cluster |
| 18 | +- [Kubectl](https://kubernetes.io/docs/reference/kubectl/kubectl/) 1.16 or higher |
| 19 | +- [Helm](https://helm.sh/) 3.0 or higher (optional) |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +You can install Orders Service (microservice or Function) either through kubectl or Helm. |
| 24 | + |
| 25 | +### Use kubectl |
| 26 | + |
| 27 | +To install the microservice on a Kyma cluster, run: |
| 28 | + |
| 29 | +```bash |
| 30 | +kubectl create ns orders-service |
| 31 | +kubectl apply -f ./deployment/orders-service-deployment.yaml |
| 32 | +kubectl apply -f ./deployment/orders-service-service.yaml |
| 33 | +``` |
| 34 | + |
| 35 | +To install the Function on a Kyma cluster, run: |
| 36 | + |
| 37 | +```bash |
| 38 | +kubectl create ns orders-service |
| 39 | +kubectl apply -f ./deployment/orders-function.yaml |
| 40 | +``` |
| 41 | + |
| 42 | +### Use Helm |
| 43 | + |
| 44 | +To install the microservice on a Kyma cluster, run: |
| 45 | + |
| 46 | +```bash |
| 47 | +helm install orders-service --namespace orders-service --create-namespace --timeout 60s --wait ./chart |
| 48 | +``` |
| 49 | + |
| 50 | +See the [`values.yaml`](./chart/values.yaml) file for the configuration of the Helm release. |
| 51 | + |
| 52 | +## Cleanup |
| 53 | + |
| 54 | +See how to remove the example from the cluster through kubectl and Helm. |
| 55 | + |
| 56 | +### Use kubectl |
| 57 | + |
| 58 | +Run this command to completely remove the microservice and all its resources from the cluster: |
| 59 | + |
| 60 | +```bash |
| 61 | +kubectl delete all -l app=orders-service -n orders-service |
| 62 | +kubectl delete ns orders-service |
| 63 | +``` |
| 64 | + |
| 65 | +Run this command to completely remove the Function and all its resources from the cluster: |
| 66 | + |
| 67 | +```bash |
| 68 | +kubectl delete all -l app=orders-function -n orders-service |
| 69 | +kubectl delete ns orders-service |
| 70 | +``` |
| 71 | + |
| 72 | +### Use Helm |
| 73 | + |
| 74 | +Run this command to completely remove the Helm release with the example and all its resources from the cluster: |
| 75 | + |
| 76 | +```bash |
| 77 | +helm delete orders-service -n orders-service |
| 78 | +kubectl delete ns orders-service |
| 79 | +``` |
| 80 | + |
| 81 | +## Configuration |
| 82 | + |
| 83 | +To configure the microservice or the Function, override the default values of these environment variables: |
| 84 | + |
| 85 | +| Environment variable | Description | Required | Default value | |
| 86 | +| ---------------------- | ----------------------------------------------------------------------------- | ------ | ------------- | |
| 87 | +| **APP_PORT** | Specifies the port of the running service. The function doesn't use this variable. | No | `8080` | |
| 88 | +| **APP_REDIS_PREFIX** | Specifies the prefix for all Redis environment variables. See the variables in other rows. | No | `REDIS_` | |
| 89 | +| **{APP_REDIS_PREFIX}HOST** | Specifies the host of the Redis instance. | No | `nil` | |
| 90 | +| **{APP_REDIS_PREFIX}PORT** | Specifies the port of the Redis instance. | No | `nil` | |
| 91 | +| **{APP_REDIS_PREFIX}REDIS_PASSWORD** | Specifies the password to authorize access to the Redis instance. | No | `nil` | |
| 92 | + |
| 93 | +See the example: |
| 94 | + |
| 95 | +```bash |
| 96 | +export APP_REDIS_PREFIX="R_" |
| 97 | +export R_HOST="abc.com" |
| 98 | +export R_PORT="8080" |
| 99 | +export R_REDIS_PASSWORD="xyz" |
| 100 | +``` |
| 101 | + |
| 102 | +> **NOTE:** To allow the microservice and the Function to communicate with the Redis instance, you must provide the **{APP_REDIS_PREFIX}HOST**, **{APP_REDIS_PREFIX}PORT**, **{APP_REDIS_PREFIX}REDIS_PASSWORD** environments. Otherwise, the microservice and the Function will always use in-memory storage. |
| 103 | +
|
| 104 | +## Testing |
| 105 | + |
| 106 | +Learn how to test both the microservice and the Function. |
| 107 | + |
| 108 | +### Microservice |
| 109 | + |
| 110 | +To send a sample order to the microservice, run: |
| 111 | + |
| 112 | +```bash |
| 113 | +curl -X POST ${APP_URL}/orders -k \ |
| 114 | + -H "Content-Type: application/json" -d \ |
| 115 | + '{ |
| 116 | + "consignmentCode": "76272727", |
| 117 | + "orderCode": "76272725", |
| 118 | + "consignmentStatus": "PICKUP_COMPLETE" |
| 119 | + }' |
| 120 | +``` |
| 121 | + |
| 122 | +To retrieve all orders saved in storage, run: |
| 123 | + |
| 124 | +```bash |
| 125 | +curl -X GET ${APP_URL}/orders -k |
| 126 | +``` |
| 127 | + |
| 128 | +**APP_URL** is the URL of the running microservice. See the [tutorial on exposing an application with an API Rule](https://github.com/kyma-project/kyma/blob/release-1.24/docs/api-gateway/08-02-exposesecure.md) for reference. |
| 129 | + |
| 130 | + |
| 131 | +> **TIP:** See the [service's OpenAPI specification](docs/openapi.yaml) for details of all endpoints. |
| 132 | +
|
| 133 | +### Function |
| 134 | + |
| 135 | +To send a sample order to the Function, run: |
| 136 | + |
| 137 | +```bash |
| 138 | +curl -X POST ${FUNCTION_URL} -k \ |
| 139 | + -H "Content-Type: application/json" -d \ |
| 140 | + '{ |
| 141 | + "consignmentCode": "76272727", |
| 142 | + "orderCode": "76272725", |
| 143 | + "consignmentStatus": "PICKUP_COMPLETE" |
| 144 | + }' |
| 145 | +``` |
| 146 | + |
| 147 | +To retrieve all orders saved in storage, run: |
| 148 | + |
| 149 | +```bash |
| 150 | +curl -X GET ${FUNCTION_URL} -k |
| 151 | +``` |
| 152 | + |
| 153 | +**FUNCTION_URL** is the URL of the running Function. See the [tutorial on exposing a Function with an API Rule](https://github.com/kyma-project/kyma/blob/release-1.24/docs/serverless/08-02-expose-function.md) for reference. |
0 commit comments