Expose multiple workloads on the same host
This tutorial shows how to expose multiple workloads on different paths by defining a service at the root level and by defining services on each path separately.
Prerequisites
- Deploy a sample HttpBin service and a sample Function.
- Set up your custom domain or use a Kyma domain instead.
Depending on whether you use your custom domain or a Kyma domain, export the necessary values as environment variables:
- Custom domain
- Kyma domain
Define multiple services on different paths
Follow the instructions to expose the instance of the HttpBin service and the sample Function on different paths at the spec.rules
level without a root service defined.
To expose the instance of the HttpBin service and the instance of the sample Function, create an APIRule CR in your Namespace. Run:
Click to copycat <<EOF | kubectl apply -f -apiVersion: gateway.kyma-project.io/v1beta1kind: APIRulemetadata:name: multiple-servicenamespace: $NAMESPACElabels:app: multiple-serviceexample: multiple-servicespec:host: multiple-service-example.$DOMAIN_TO_EXPOSE_WORKLOADSgateway: $GATEWAYrules:- path: /headersmethods: ["GET"]accessStrategies:- handler: noopservice:name: httpbinport: 8000- path: /functionmethods: ["GET"]accessStrategies:- handler: noopservice:name: functionport: 80EOFTo call the endpoints, send
GET
requests to the HttpBin service and the sample Function:Click to copycurl -ik -X GET https://multiple-service-example.$DOMAIN_TO_EXPOSE_WORKLOADS/headerscurl -ik -X GET https://multiple-service-example.$DOMAIN_TO_EXPOSE_WORKLOADS/functionIf successful, the calls return the code
200 OK
response.
Define a service at the root level
A service can be also defined at the root level. Such a definition is applied to all the paths specified at the spec.rules
which do not have their own services defined.
NOTE: Services definitions at the
spec.rules
level have precedence over service definition at thespec.service
level.
Follow the instructions to expose the instance of the HttpBin service and the sample Function on different paths with a service defined at the root level.
To expose the instance of the HttpBin service and the instance of the sample Function, create an APIRule CR in your Namespace. Run:
Click to copycat <<EOF | kubectl apply -f -apiVersion: gateway.kyma-project.io/v1beta1kind: APIRulemetadata:name: multiple-servicenamespace: $NAMESPACElabels:app: multiple-serviceexample: multiple-servicespec:host: multiple-service-example.$DOMAIN_TO_EXPOSE_WORKLOADSgateway: $GATEWAYservice:name: httpbinport: 8000rules:- path: /headersmethods: ["GET"]accessStrategies:- handler: noop- path: /functionmethods: ["GET"]accessStrategies:- handler: noopservice:name: functionport: 80EOFIn the above APIRule, the HttpBin service on port 8000 is defined at the
spec.service
level. This service definition is applied to the/headers
path. The/function
path has the service definition overwritten.To call the endpoints, send
GET
requests to the HttpBin service and the sample Function:Click to copycurl -ik -X GET https://multiple-service-example.$DOMAIN_TO_EXPOSE_WORKLOADS/headerscurl -ik -X GET https://multiple-service-example.$DOMAIN_TO_EXPOSE_WORKLOADS/functionIf successful, the calls return the code
200 OK
response.