


Using this design approach, every type of request a device can send may be modelled as a service and deployed on a cluster of servers, otherwise known as the cloud. Microservices are usually exposed as RESTful HTTP APIs, meaning they allow a client to access and manipulate data through requests such as GET, POST, PUT and DELETE.


Feathers is an open-source Node.js web framework, acting as a REST and real-time API layer for modern applications. [2] The latter bit means that it's ideal for building RESTful APIs, especially using a microservice architecture. A RESTful API is inherently stateless, which means that there may be multiple copies of the API spun up and the client shouldn't care which copy they're talking to. This is perfect for scalability, since the number of copies of a device end-point can be adjusted depending on how busy the entire system is.


Kubernetes is a recent advancement in cloud computing, allowing seamless deployment, management and scaling of containerised applications. It works by letting you define the workloads you want to run and the services you want to expose. This gives fine-grain control over how microservices and clients talk to each other. From there, workloads can be updated, scaled up or down, depending on how the application is performing. In one foul swoop, Kubernetes eliminates worries about setting up, managing and scaling servers/applications, which is really helpful in rapid prototyping.


Lastly, what's the point of an API if the devices don't know who to talk to? Ingress is used in Kubernetes to allow inbound connections to reach the cluster services. [3] In this case, it is configured using Google Kubernetes Engine (GKE) to give services externally-reachable URLs and to load balance traffic.

The Problem

By default, Ingress on GKE comes with built-in health checks for any services you expose using a controller. This is good for basic workloads, such as an nginx container, where serving internal server error messages could lead to sensitive data being leaked.

However, the way Ingress does it by default is a bit too simple for a RESTful API:

All Kubernetes services must serve a 200 page on '/'

By default, Ingress will send an HTTP GET request to '/'. This is alright for containers such as nginx, as it will just hit the root of the public directory.

From a RESTful API point of view, Ingress is sending a find() request to the '/' service (nothing specified before the slash). While it would make sense to have a catch-all index service that supports requests on '/', Feathers.JS explicitly doesn't allow that.

The semi-official reason for this is that a slash gets truncated in a service name so it will result in an empty string, which makes for a bad service identifier, especially when you're doing something fancy with it. [4]

The Fix

Defining a custom health check in Kubernetes

GKE Ingress only falls back to its default health check if there is no custom one specified in the workload definitions. The GKE implementation of Ingress pulls custom health checks from the readinessProbe definition in a Deployment's contain spec. This may be defined as follows:

apiVersion: extensions/v1beta1
kind: Deployment
  name: restfulapi-deployment
    app: restfulapi
  replicas: 3
      app: restfulapi
        app: restfulapi
      - name: bitbucket-thinkengineer-restfulapi
        - containerPort: 3030
         - configMapRef:
             name: config
        # Custom healthcheck for Ingress
            path: /health
            port: 3030
          initialDelaySeconds: 5
          timeoutSeconds: 5

Some forum posts reportedly state that having a containerPort defined also helps. From here, your service for the workload may be exposed as normal using Ingress:

apiVersion: v1
kind: Service
  name: restfulapi-service
    app: restfulapi
  type: NodePort
  - name: restfulapi
    protocol: TCP
    port: 3030
    targetPort: 3030

apiVersion: extensions/v1beta1
kind: Ingress
  name: ingress
  annotations: ingress /
  - host:
      - path: /*
          serviceName: restfulapi-service
          servicePort: 3030

Implementing a custom health check in Feathers.JS

In the above definitions, you may see that we're now checking '/health' as opposed to '/'. Since the service name is no longer an empty string, we can create a Feathers service to respond to requests send there. This may be done as follows:

/* Create Feathers appication */
const restAPI = express(feathers())
.use(express.urlencoded({ extended: true }))
.use('/rest', restService)

/* Register health API */
.use('/health', {
    async find(params) { 
        return `restAPI still alive`

/* Start the server */
.listen(API_PORT).on('listening', () =>
    console.log(`restAPI listening on ${API_URL}`)

The newly created '/health' service is quite simple - it simply returns a string, along with a 200 status code. This is enough to satisfy Ingress and make the health check pass to get traffic routed to your service/workload.


Overall, when prototyping, you tend to work with new technologies that may not have necessarily been designed to work together. I know in this case the only thing I had to go on were GitHub issues. Although it seems like a straight-forward fix, figuring it out was a massive gotcha. I've talked to some Kubernetes developers about Ingress ever since and they've seemed to agree that its implementation on GKE tends to cause a lot of problems such as this.


[1] - J. Rulifson, "Decode Encode LAnguage (DEL)", Network Working Group RFC-5, June 2 1969.

[2] - Feathers Contributors, Feathers.JS, Feathers.

[3] - The Kubernetes Authors, "Ingress", Kubernetes.

[4] - keesee, daffl, "Service at root. '/'", Feathers.