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.
Here's an example which would use 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
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: router-testlabels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: router-testapp.kubernetes.io/version: "v0.9.2"---# Source: router/templates/secret.yamlapiVersion: v1kind: Secretmetadata:name: router-testlabels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: router-testapp.kubernetes.io/version: "v0.9.2"data:managedFederationApiKey: "REDACTED"---# Source: router/templates/configmap.yamlapiVersion: v1kind: ConfigMapmetadata:name: router-testlabels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: router-testapp.kubernetes.io/version: "v0.9.2"data:configuration.yaml: |server:listen: 0.0.0.0:80telemetry:metrics:prometheus:enabled: true---# Source: router/templates/service.yamlapiVersion: v1kind: Servicemetadata:name: router-testlabels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: router-testapp.kubernetes.io/version: "v0.9.2"spec:type: ClusterIPports:- port: 80targetPort: httpprotocol: TCPname: httpselector:app.kubernetes.io/name: routerapp.kubernetes.io/instance: router-test---# Source: router/templates/deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: router-testlabels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: router-testapp.kubernetes.io/version: "v0.9.2"annotations:prometheus.io/path: /plugins/apollo.telemetry/prometheusprometheus.io/port: "80"prometheus.io/scrape: "true"spec:replicas: 1selector:matchLabels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: router-testtemplate:metadata:labels:app.kubernetes.io/name: routerapp.kubernetes.io/instance: router-testspec:serviceAccountName: router-testsecurityContext:{}containers:- name: routersecurityContext:{}image: "ghcr.io/apollographql/router:v0.9.2"imagePullPolicy: IfNotPresentargs:- --hot-reload- --config- /app/configuration.yamlenv:- name: APOLLO_KEYvalueFrom:secretKeyRef:name: router-testkey: managedFederationApiKey- name: APOLLO_GRAPH_REFvalue: "REDACTED"ports:- name: httpcontainerPort: 80protocol: TCPlivenessProbe:httpGet:path: /.well-known/apollo/server-healthport: httpreadinessProbe:httpGet:path: /.well-known/apollo/server-healthport: httpresources:{}volumeMounts:- name: router-configurationmountPath: /app/configuration.yamlsubPath: configuration.yamlreadOnly: truevolumes:- name: router-configurationconfigMap:name: router-test
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 4000 on your localhost, you could exercise the health endpoint as follows:
curl "http://localhost:4000/.well-known/apollo/server-health"{"status":"pass"}
This health endpoint can be used to check the health of the router. It will always return a status of pass if all is well.