# Mender-api-gateway liveness fails (seems like?)

**URL:** https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082
**Category:** General Discussions
**Tags:** mender-server
**Created:** [September 15, 2021, 1:32am UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082 "2021-09-15T01:32:43Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![gigilibala](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/gigilibala/32/1366_2.png) [@gigilibala](https://hub.mender.io/u/gigilibala)
#### Post date: [September 15, 2021, 1:32am UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/1 "2021-09-15T01:32:43Z")

</div>

Hi all,

Thanks all for creating such a great project. I’m setting up a mender server 3.0.0. in a kubernetes cluster using the helm charts. However the problem is setting an Ingress for external HTTP(s) load balancing doesn’t work. For the mender-api-gateway service below:

 ![Screen Shot 2021-09-14 at 6.21.23 PM](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/2X/5/53e5fbf2e8b8fcc6857c6283b94cc143e5317e31.png)

I setup a LoadBalancer mender-api-gateway-lb as below:

 ![Screen Shot 2021-09-14 at 6.21.57 PM](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/2X/7/7d154db8d50aa36fa836ded743d43b21be97badf.png)

Everything works fine if I port forward the LB service and I can easily access the mender UI and login with no problem. However, when I setup an ingress over this load balancer, it does not work. Accessing the website gives an 502 (bad gateway) error.

 ![Screen Shot 2021-09-14 at 6.25.17 PM](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/2X/f/f86f6259cf6d2f45db86e545948f92bec987c991.png)

Looking at the ingress description, it clearly says that backend is unhealthy (first one is the default backend which is healthy). Which means probably the liveness or readiness probes of the mender-api-gateway doesn’t work. I can confirm this because if I setup a dummy hello world backend for the ingress, it works perfectly fine (HEALTHY). But the mender server doesn’t.

Any idea what is wrong here? And what maybe the remedy?

Thank you.

---

<div class="post-metadata">

### Author: ![gigilibala](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/gigilibala/32/1366_2.png) [@gigilibala](https://hub.mender.io/u/gigilibala)
#### Post date: [September 15, 2021, 6:43pm UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/2 "2021-09-15T18:43:42Z")

</div>

Looking around, one reason for this could be that since the gateway redirects URL with 302 code, it will unacceptable by the kubernetes ingress controller which requires port response 200 only. That’s what I’ve go so far. If mender api gateway would implement the readiness and aliveness with httpGet to a known path (/healthz) instead of tcpPort, it could probably work.

---

<div class="post-metadata">

### Author: ![gigilibala](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/gigilibala/32/1366_2.png) [@gigilibala](https://hub.mender.io/u/gigilibala)
#### Post date: [September 15, 2021, 7:49pm UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/3 "2021-09-15T19:49:52Z")

</div>

per [Configuring Ingress features &nbsp;|&nbsp; Kubernetes Engine Documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-features#direct_health) GKE does not support TCP healthchecks so ingress cannot be setup for mender-api-gateway. I think this is a bug on mender that needs to be fixed.

---

<div class="post-metadata">

### Author: ![tranchitella](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/tranchitella/32/606_2.png) [@tranchitella](https://hub.mender.io/u/tranchitella)
#### Post date: [September 15, 2021, 7:52pm UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/4 "2021-09-15T19:52:25Z")

</div>

@gigilibala you need to customize the healthcheck in your ingress:

> **[Configuring Ingress features  |  Kubernetes Engine Documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-features#direct_health)**

I’d suggest to set `requestPath: /ui/` to get a 200 OK.

---

<div class="post-metadata">

### Author: ![gigilibala](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/gigilibala/32/1366_2.png) [@gigilibala](https://hub.mender.io/u/gigilibala)
#### Post date: [September 15, 2021, 8:59pm UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/5 "2021-09-15T20:59:07Z")

</div>

Thanks. Yeah, I tried a few paths that return 200 including this, unfortunately the backend still shows unhealthy ☹

---

<div class="post-metadata">

### Author: ![gigilibala](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/gigilibala/32/1366_2.png) [@gigilibala](https://hub.mender.io/u/gigilibala)
#### Post date: [September 16, 2021, 12:01am UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/6 "2021-09-16T00:01:51Z")

</div>

We were able to fix it by using the containrPort instead of 80 for BackendConfig. That gave it away. Thanks 🙂

---

<div class="post-metadata">

### Author: ![tranchitella](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/tranchitella/32/606_2.png) [@tranchitella](https://hub.mender.io/u/tranchitella)
#### Post date: [September 16, 2021, 3:19am UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/7 "2021-09-16T03:19:26Z")

</div>

@gigilibala Thanks, would you mind sharing an excerpt of your configuration here so people facing the same issue in GCP with Ingresses can find the answer?

---

<div class="post-metadata">

### Author: ![gigilibala](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/gigilibala/32/1366_2.png) [@gigilibala](https://hub.mender.io/u/gigilibala)
#### Post date: [September 16, 2021, 8:49pm UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/8 "2021-09-16T20:49:14Z")

</div>

@tranchitella  
Sure, here it goes. I think this would be good to add to the [example Ingress](https://docs.mender.io/3.0/server-installation/production-installation-with-kubernetes/mender-server). That example alone without the following does not work.

You need to setup a BackendConfig to change the healthcheck config of ingress.

```auto
apiVersion: cloud.google.com/v1beta1
kind: BackendConfig
metadata:
  name: mender-api-gateway-backend
spec:
  healthCheck:
    type: HTTP
    # mender-api-gateway redirects the root path to /ui/, but the Ingress
    # healthcheck by default uses / (root) and expects 200 code. Changing the
    # request path here fixes that issue.
    requestPath: /ui/

```

Then add the following annotation to the k8s service that ingress is pointing to:

```auto
cloud.google.com/backend-config: '{"ports": {"80":"mender-api-gateway-backend"}}'

```

Then ingress should be able to do proper healthcheck.

---

<div class="post-metadata">

### Author: ![tranchitella](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/tranchitella/32/606_2.png) [@tranchitella](https://hub.mender.io/u/tranchitella)
#### Post date: [September 17, 2021, 3:59am UTC](https://hub.mender.io/t/mender-api-gateway-liveness-fails-seems-like/4082/9 "2021-09-17T03:59:20Z")

</div>

Thanks for sharing, @gigilibala
