Expose a workload
This tutorial shows how to expose service endpoints and configure different allowed HTTP methods for them using API Gateway Controller.
The tutorial may be a follow-up to the Set up a custom domain for a workload tutorial.
Prerequisites
This tutorial is based on a sample HttpBin service deployment and a sample Function. To deploy or create one of those, follow the Create a workload tutorial.
Expose and access your workload
Follow the instruction to expose and access your unsecured instance of the HttpBin service or unsecured sample Function.
- HttpBin
- Function
Export the following value as an environment variable:
Click to copyexport DOMAIN_TO_EXPOSE_WORKLOADS={DOMAIN_NAME}export GATEWAY=$NAMESPACE/httpbin-gatewayNOTE:
DOMAIN_NAME
is the domain that you own, for example, api.mydomain.com. If you don't want to use your custom domain, replaceDOMAIN_NAME
with a Kyma domain and$NAMESPACE/httpbin-gateway
with Kyma's default Gatewaykyma-system/kyma-gateway
Expose the instance of the HttpBin service by creating an APIRule CR in your Namespace. Run:
Click to copycat <<EOF | kubectl apply -f -apiVersion: gateway.kyma-project.io/v1beta1kind: APIRulemetadata:name: httpbinnamespace: $NAMESPACEspec:host: httpbin.$DOMAIN_TO_EXPOSE_WORKLOADSservice:name: httpbinnamespace: $NAMESPACEport: 8000gateway: $GATEWAYrules:- path: /.*methods: ["GET"]accessStrategies:- handler: noopmutators:- handler: noop- path: /postmethods: ["POST"]accessStrategies:- handler: noopmutators:- handler: noopEOFNOTE: If you are running Kyma on k3d, add
httpbin.kyma.local
to the entry with k3d IP in your system's/etc/hosts
file.NOTE: If you don't specify a Namespace for your service, the default APIRule Namespace is used.
Call the endpoint by sending a
GET
request to the HttpBin service:Click to copycurl -ik -X GET https://httpbin.$DOMAIN_TO_EXPOSE_WORKLOADS/ipSend a
POST
request to the HttpBin's/post
endpoint:Click to copycurl -ik -X POST https://httpbin.$DOMAIN_TO_EXPOSE_WORKLOADS/post -d "test data"These calls return the code
200
response.