New to Voyager? Please start here.

Server Health Check

You can enable haproxy-health-checks for a specific backend server by applying ingress.appscode.com/check and ingress.appscode.com/check-port annotations to the corresponding service. You can also configure health-check behavior using backend rules.

Example

First deploy and expose a test server:

$ kubectl apply -f test-server.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: test-server
  name: test-server
  namespace: default
spec:
  selector:
    matchLabels:
      run: test-server
  template:
    metadata:
      labels:
        run: test-server
    spec:
      containers:
      - image: appscode/test-server:2.2
        name: test-server
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: test-server
  name: test-server
  namespace: default
spec:
  ports:
  - port: 8080
    targetPort: 8080
    name: web
  - port: 9090
    targetPort: 9090
    name: health
  selector:
    run: test-server

Here, port 8080 will serve client’s request and port 9090 will be used for health checks.

Then deploy the ingress:

$ kubectl apply test-ingress.yaml

apiVersion: voyager.appscode.com/v1
kind: Ingress
metadata:
  name: test-ingress
  namespace: default
spec:
  rules:
  - http:
      paths:
      - path: /app
        backend:
          service:
            name: test-server
            port:
              number: 8080

Now we need to annotate the backend service to enable health check for that backend.

$ kubectl annotate svc test-server ingress.appscode.com/check="true"
$ kubectl annotate svc test-server ingress.appscode.com/check-port="9090"

You can also specify the health-check behaviour using backend rules. For example:

apiVersion: voyager.appscode.com/v1
kind: Ingress
metadata:
  name: test-ingress
  namespace: default
spec:
  rules:
  - http:
      paths:
      - path: /app
        backend:
          service:
            name: test-server
            port:
              number: 8080
          backendRules:
          - 'option httpchk GET /testpath/ok'
          - 'http-check expect rstring (testpath/ok)'