Deploy and expose a microservice

You already know how to deploy and expose a Function. Let's now do the same with a container microservice. We'll use the Kyma example orders-service for this.

Deploy the microservice

First, let's create a Deployment that provides the microservice definition and lets you run it on the cluster.

  • Kyma Dashboard
  • kubectl
  1. From the left navigation, go to Workloads > Deployments.
  1. Click on Create Deployment.
  1. Go to Advanced and provide the following parameters:

    • Name: orders-service
    • Docker Image: eu.gcr.io/kyma-project/develop/orders-service:68a58069
      Optionally, to save resources, modify these parameters:
    • Memory requests: 10Mi
    • Memory limits: 32Mi
    • CPU requests (m): 16m
    • CPU limits (m): 20m
  2. Click Create.

The operation was successful if you can see 1/1 Pods running in the Deployment's view.

Create the Service

Now that we have the Deployment, let's deploy the Kubernetes Service to allow other Kubernetes resources to communicate with your microservice.

  • Kyma Dashboard
  • kubectl
  1. From the left navigation, go to Discovery and Network > Services.
  1. Click on Create Service.
  1. In the Create Service view, paste the following values to your YAML file:

    Click to copy
    apiVersion: v1
    kind: Service
    metadata:
    name: orders-service
    spec:
    selector:
    app: orders-service
    ports:
    - protocol: TCP
    port: 80
    targetPort: 8080
  2. Click Create.

Expose the microservice

We have created the Service. Let's now expose it outside the cluster.

CAUTION: Exposing a workload to the outside world is always a potential security vulnerability, so tread carefully. In a production environment, always secure the workload you expose with OAuth2 or JWT.

To expose our microservice, we must create an APIRule CR for it, just like when we exposed our Function.

  • Kyma Dashboard
  • kubectl
  1. Go to Discovery and Network > API Rules, and click on Create API Rule.
  1. Provide the Name (orders-service)
  1. Choose orders-service from the Service Name dropdown.
  1. Provide your Service Port (80).
  1. Choose your host from the Host dropdown and replace the asterisk (*) with the name of your subdomain (orders-service).
  1. Click Create.

Verify the microservice exposure

Now let's check that the microservice has been exposed successfully.

  • Kyma Dashboard
  • kubectl
  1. From your Service's view, get the APIRule's Host.

    NOTE: Alternatively, from the left navigation go to API Rules and get the Host URL from there.

  1. Paste this Host in your browser and add the /orders suffix to the end of it, like this: {HOST}/orders. Open it.

The operation was successful if the page shows the (possibly empty []) list of orders.