Addition of a Discovery Service#

Goal: Deploy the Discovery Service so clients and services can find each other via a single entrypoint that returns a JSON list of services and endpoints (local MicroK8s deployment).

The Discovery Service defines the services in your deployment and exposes a single endpoint. Clients request {hostname}:{port}/api/v1/services and receive a JSON object with service information.

Service Ports#

Port

Protocol

Description

8080

HTTP/REST

Discovery API endpoint (/api/v1/services)

Pulling the Discovery Service Helm Chart#

Pull the Discovery Service Helm chart from the NGC catalog. Use the same {NGC_API_KEY} you used for earlier services.

# pull the chart from NGC
# make sure you have enabled helm in microk8s
microk8s enable helm
# pull the chart from NGC
microk8s helm fetch https://helm.ngc.nvidia.com/nvidia/omniverse/charts/discovery-service-2.3.8.tgz --username='$oauthtoken' --password=${NGC_API_KEY}

# unpack the chart and cd into the directory
tar -xvf discovery-service-2.3.8.tgz
cd discovery-service

Configure Overrides for the Discovery Service#

Override only the values you need. Create discovery-values.yaml in the same directory as the Helm chart.

# create and edit the local values file, we're using VS Code for this example
code discovery-values.yaml

If you removed the namespace after the storage service, recreate it.

# create the namespace
microk8s kubectl create namespace storage-apis-dev

# validate the namespace was created
microk8s kubectl get namespace storage-apis-dev

Pull Secrets#

Create a pull secret so the cluster can pull images from the registry. Replace {NGC_API_KEY} with your NGC API key.

Note

Expand {NGC_API_KEY} to the full value in the command; kubectl may not expand the variable.

# create a Kubernetes secret with the pull secret
microk8s kubectl create secret docker-registry ngcpull-secret --docker-server=nvcr.io --docker-username='$oauthtoken' --docker-password=${NGC_API_KEY} -n storage-apis-dev

# validate the secret was created
microk8s kubectl get secret ngcpull-secret -n storage-apis-dev

Reference the secret in discovery-values.yaml so the cluster can pull the images.

image:
  pullSecrets:
    - name: ngcpull-secret

discovery-values.yaml

Discovery Schema#

The Discovery Service responds with a JSON object describing each service in the deployment. Current schema:

 1{
 2    "schema-version": 1,
 3    "services": [
 4        {
 5            "id": "service-service-id...",
 6            "name": "service-name",
 7            "type": "service-type",
 8            "rest": "https://{service-hostname}:{service-port}",
 9            "grpc": "grpc://{service-hostname}:{service-port}"
10        }
11    ]
12}

Schema fields (used by Kit-based apps to discover services):

  • id: Unique identifier for the service.

  • name: Human-readable name.

  • type: Service type.

  • rest: REST endpoint (use http as the prefix for non-TLS). Optional; only for REST clients.

  • grpc: gRPC endpoint (use http as the prefix for non-TLS). Optional; only for gRPC clients.

Set the Discovery Response#

Configure the Discovery Service to include the storage service. The fully qualified hostname is built at deploy time from the host, namespace, and port:

  • tls: truehttps, falsehttp

  • host: Service name (e.g. storage-service)

  • port: Service port

Example: in namespace storage-apis-dev, the storage service is http://storage-service.storage-apis-dev.svc.cluster.local with the ports below.

discovery:
  services:
    - id: "storage-service-01"
      name: "Storage Service"
      type: "storage"
      endpoints:
        grpc:
          host: ""
          port: 50051
          path: "/"
          tls: false
        rest:
          host: ""
          port: 8011
          path: "/"
          tls: false

discovery-values.yaml

Install the Discovery Service.

# validate the chart
microk8s helm template . -f discovery-values.yaml

# dry-run the install
microk8s helm upgrade --install discovery-service . -f discovery-values.yaml --namespace storage-apis-dev --dry-run --debug

If everything looks good, you can install the Discovery Service.

# install the discovery service
microk8s helm upgrade --install discovery-service . -f discovery-values.yaml --namespace storage-apis-dev

# validate the pod is running, this may take a few minutes to start up
microk8s kubectl get pods -n storage-apis-dev

Validate the Discovery Service is working#

Use port-forwarding to test the Discovery Service.

# set up port forwarding
microk8s kubectl port-forward -n storage-apis-dev service/discovery-service 8080:8080

# test the discovery service
curl http://localhost:8080/api/v1/services

You should see a JSON response listing the services in the deployment.

Cleanup#

To clean up: uninstall the Helm release and delete the namespace.

# uninstall the discovery service
microk8s helm uninstall discovery-service -n storage-apis-dev

# delete the namespace
microk8s kubectl delete namespace storage-apis-dev

# validate the namespace was deleted
microk8s kubectl get namespace storage-apis-dev

Next Steps#

Next: create a Kubernetes deployment that uses the Discovery and Storage services together.