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
- From the left navigation, go to Workloads > Deployments.
- Click on Create Deployment.
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
- Name:
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
- From the left navigation, go to Discovery and Network > Services.
- Click on Create Service.
In the Create Service view, paste the following values to your YAML file:
Click to copyapiVersion: v1kind: Servicemetadata:name: orders-servicespec:selector:app: orders-serviceports:- protocol: TCPport: 80targetPort: 8080Click Create.
Expose the microservice
We have created the Service. Let's now expose it outside the cluster.
To expose our microservice, we must create an APIRule CR for it, just like when we exposed our Function.
- Kyma Dashboard
- kubectl
- Go to Discovery and Network > API Rules, and click on Create API Rule.
- Provide the Name (
orders-service
)
- Choose
orders-service
from the Service Name dropdown.
- Provide your Service Port (
80
).
- Choose your host from the Host dropdown and replace the asterisk (*) with the name of your subdomain (
orders-service
).
Click Create.
Verify the microservice exposure
Now let's check that the microservice has been exposed successfully.
- Kyma Dashboard
- kubectl
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.
- 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.