Kubernetes and the router
Using router images with kubernetes
Sample Kubernetes Configuration
Note: The Apollo Router is made available under the Elastic License v2.0 (ELv2). This applies to its source code and all distributions, including versions installed via Helm charts. Read our licensing page for more details.
Helm
Helm is the package manager for kubernetes.
There is a complete helm chart definition in the repo which illustrates how to use helm to deploy the router in kubernetes.
In both the following examples, we are using helm to install the router:
- into namespace "router-deploy" (create namespace if it doesn't exist)
- with helm install name "router-test"
- with support for prometheus enabled
Using helm chart from our Open Container Initiative (OCI) registry
Starting with release 0.14.0, each time we release the router, we'll release our helm chart and store it in the same OCI registry in which we store our router docker images.
You can use helm to install charts from an OCI registry as follows:
helm install --set router.configuration.telemetry.metrics.prometheus.enabled=true --set managedFederation.apiKey="REDACTED" --set managedFederation.graphRef="REDACTED" --create-namespace --namespace router-deploy router-test oci://ghcr.io/apollographql/helm-charts/router --version 1.0.0-rc.8 --values router/values.yaml
For more details about using helm with OCI based registries, see here
Using helm chart from your filesystem
You would run this command from "repo"/helm/chart directory.
(where "repo" is the directory containing your checked out router github repository)
helm install --set router.configuration.telemetry.metrics.prometheus.enabled=true --set managedFederation.apiKey="REDACTED" --set managedFederation.graphRef="REDACTED" --create-namespace --namespace router-deploy router-test router --values router/values.yaml
Once executed, you can check the status of the helm deploy:
helm list --namespace router-deploy
Kubernetes Configuration
If you aren't familiar with helm, the following example illustrates how you could do the same thing manually or as a base for kustomize.
Note: This example is generated using the helm template capability to generate the required kubernetes configuration from our helm chart. After generation, it is edited to remove the Helm management annotations.
---# Source: router/templates/serviceaccount.yamlapiVersion: v1kind: ServiceAccountmetadata:name: release-name-routerlabels:helm.sh/chart: router-1.20.0app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-nameapp.kubernetes.io/version: "v1.20.0"app.kubernetes.io/managed-by: Helm---# Source: router/templates/secret.yamlapiVersion: v1kind: Secretmetadata:name: "release-name-router"labels:helm.sh/chart: router-1.20.0app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-nameapp.kubernetes.io/version: "v1.20.0"app.kubernetes.io/managed-by: Helmdata:managedFederationApiKey: "UkVEQUNURUQ="---# Source: router/templates/configmap.yamlapiVersion: v1kind: ConfigMapmetadata:name: release-name-routerlabels:helm.sh/chart: router-1.20.0app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-nameapp.kubernetes.io/version: "v1.20.0"app.kubernetes.io/managed-by: Helmdata:configuration.yaml: |health_check:listen: 0.0.0.0:8088supergraph:listen: 0.0.0.0:80telemetry:metrics:common:resources:service.name: release-name-routerprometheus:enabled: truelisten: 0.0.0.0:9090path: /metrics---# Source: router/templates/service.yamlapiVersion: v1kind: Servicemetadata:name: release-name-routerlabels:helm.sh/chart: router-1.20.0app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-nameapp.kubernetes.io/version: "v1.20.0"app.kubernetes.io/managed-by: Helmspec:type: ClusterIPports:- port: 80targetPort: httpprotocol: TCPname: http- port: 8088targetPort: healthprotocol: TCPname: healthselector:app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-name---# Source: router/templates/deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: release-name-routerlabels:helm.sh/chart: router-1.20.0app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-nameapp.kubernetes.io/version: "v1.20.0"app.kubernetes.io/managed-by: Helmannotations:prometheus.io/path: /metricsprometheus.io/port: "9090"prometheus.io/scrape: "true"spec:replicas: 1selector:matchLabels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-nametemplate:metadata:labels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-namespec:serviceAccountName: release-name-routersecurityContext:{}containers:- name: routersecurityContext:{}image: "ghcr.io/apollographql/router:v1.20.0"imagePullPolicy: IfNotPresentargs:- --hot-reload- --config- /app/configuration.yamlenv:- name: APOLLO_KEYvalueFrom:secretKeyRef:name: "release-name-router"key: managedFederationApiKeyoptional: true- name: APOLLO_GRAPH_REFvalue: REDACTEDports:- name: httpcontainerPort: 80protocol: TCP- name: healthcontainerPort: 8088protocol: TCPlivenessProbe:httpGet:path: "/health"port: 8088initialDelaySeconds: 0readinessProbe:httpGet:path: "/health"port: 8088initialDelaySeconds: 0resources:{}volumeMounts:- name: router-configurationmountPath: /app/readOnly: truevolumes:- name: router-configurationconfigMap:name: release-name-routerterminationGracePeriodSeconds: 30---# Source: router/templates/tests/test-connection.yamlapiVersion: v1kind: Podmetadata:name: "release-name-router-test-connection"labels:helm.sh/chart: router-1.20.0app.kubernetes.io/name: routerapp.kubernetes.io/instance: release-nameapp.kubernetes.io/version: "v1.20.0"app.kubernetes.io/managed-by: Helmannotations:"helm.sh/hook": testspec:containers:- name: netcatimage: busyboxcommand: ['nc']args: ['-vz','-w','1','release-name-router:80']restartPolicy: Never
The health endpoint
The router supports a health endpoint. You can see from the examples above how it can be used in a kubernetes deployment.
If you had a router running on port 8088 on your localhost, you could exercise the health endpoint as follows:
curl "http://localhost:8088/health"{"status":"UP"}
If you had a router running on your localhost, with default health-check configuration, you could exercise the health endpoint as follows:
curl "http://localhost:8088/health"