Exposing a Service in Kyma with APIRules

Objective

After completing this lesson, you will be able to create APIRules to expose and secure services

Expose a Service in Kyma with APIRules

Usage Scenario

You have already deployed your application to a Kubernetes cluster and created a Service for it. To expose this Service to the outside world, you must create an APIRule.

Task Flow

In this exercise, you will perform the following tasks:

  1. Expose a Service with an APIRule.
  2. Test the exposed Service.

Prerequisites

Before you begin, ensure that the following prerequisites are met:

Task 1: Expose a Service with an APIRule Custom Resource

Steps

  1. Create a file named hello-kyma-api-rule.yaml with the following content:

    YAML
    123456789101112131415
    apiVersion: gateway.kyma-project.io/v2 kind: APIRule metadata: name: hello-kyma spec: hosts: - hello-kyma.<hostname> # replace <hostname> with your Kyma hostname service: name: hello-kyma-svc port: 80 gateway: kyma-system/kyma-gateway rules: - path: /* methods: ["GET"] noAuth: true
  2. Retrieve the hostname from your SAP BTP, Kyma runtime and adjust the host in the APIRule manifest.

    Code Snippet
    1
    kubectl get gateway kyma-gateway -n kyma-system -o=jsonpath='{.spec.servers[0].hosts[0]}'

    Note

    Be aware that this command is returning the wildcard hostname.
  3. Apply the APIRule manifest to the cluster.

    Code Snippet
    1
    kubectl apply -f hello-kyma-api-rule.yaml
  4. Access the application in your browser.

    1. Open a web browser.

    2. Navigate to the URL http://hello-kyma.<hostname> (replace with your Kyma hostname).

    3. You should see a greeting from the hello-kyma application.

Task 2: View APIRules in Kyma Dashboard

Steps

  1. Go to the APIRules section of Kyma dashboard.

    1. Open Kyma dashboard in your web browser. You can find the link in the Kyma Environment section of your subaccount.

    2. Select API Rules and choose the hello-kyma APIRule.

    3. Verify the details, copy the host link, and paste the link into your browser.

      Exposed Service
    4. If successful, the browser displays the greeting from your hello-kyma application.

Result

You have successfully exposed your service with an APIRule.