Getting 502 Bad Gateway nginx/1.13.9 for my angular app in k8's

1/7/2020

I am getting 502 Bad Gateway nginx/1.13.9 for my angular app when accessing in the browser in k8's. My service and ingress is as below.

Angular app pod logs show all successful and in-fact port forwarding is working fine. This same image is also working fine in my local machine with docker.

From k8s logs, I could see this:

[error] 1534#1534: *32272457 SSL_do_handshake() failed (SSL: error:1408F10B:SSL routines:ssl3_get_record:wrong version number) while SSL handshaking to upstream

Service:


Name:              test-portal
Namespace:         testproject
Labels:            app=test-portal
                   chart=test-portal-1.0.0
                   environment=dev
                   heritage=Tiller
                   release=test-portal
                   version=dev
Annotations:       <none>
Selector:          app=test-portal,release=test-portal
Type:              ClusterIP
IP:                x.x.x.x
Port:              <unset>  80/TCP
TargetPort:        4200/TCP
Endpoints:         x.x.x.x:4200
Session Affinity:  None
Events:            <none>

Ingress:


Name:             test-portal
Namespace:        testproject
Address:
Default backend:  default-http-backend:80 (<none>)
TLS:
  SNI routes test-portal.us-west-2.xxxxx.xxxxxx.delivery
Rules:
  Host                                                       Path  Backends
  ----                                                       ----  --------
  test-portal.us-west-2.xxxxx.xxxxxx.delivery
                                                             /  test-portal:80 (<none>)
Annotations:
  secure-backends:  true
  ssl-redirect:     true
Events:             <none>

Ingress Config map


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/secure-backends: "false"
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"ingress.kubernetes.io/secure-backends":"false","kubernetes.io/ingress.class":"nginx"},"labels":{"app":"test-portal","chart":"test-portal-1.0.0","environment":"dev","heritage":"test-portal","release":"Helm","version":"1.0.0"},"name":"test-portal","namespace":"testproject"},"spec":{"rules":[{"host":"test-portal.us-west-2.xxxx.xxxxxxxxx.delivery","http":{"paths":[{"backend":{"serviceName":"test-portal","servicePort":80},"path":"/"}]}}],"tls":[{"hosts":["test-portal.us-west-2.xxxx.xxxxxxxxx.delivery"]}]}}
    kubernetes.io/ingress.class: nginx
  creationTimestamp: 2020-01-08T11:24:18Z
  generation: 1
  labels:
    app: test-portal
    chart: test-portal-1.0.0
    environment: dev
    heritage: test-portal
    release: Helm
    version: 1.0.0
  name: test-portal
  namespace: testproject
  resourceVersion: "2379156945"
  selfLink: /apis/extensions/v1beta1/namespaces/testproject/ingresses/test-portal
  uid: 6925819b-3209-11ea-80fb-02fb0c9060d8
spec:
  rules:
  - host: test-portal.us-west-2.xxxx.xxxxxxxxx.delivery
    http:
      paths:
      - backend:
          serviceName: test-portal
          servicePort: 80
        path: /
  tls:
  - hosts:
    - test-portal.us-west-2.xxxx.xxxxxxxxx.delivery
status:
  loadBalancer:
    ingress:
    - {}
-- Karthik Reddy
amazon-web-services
angular
kubernetes
kubernetes-ingress
node.js

1 Answer

1/7/2020

You seem to be running the angular dev server on port 4200 in your pod. The angular app is served using http, not https, therefore you must configure the ingress to not use https (secure-backends: false) for backend communication.

Besides, the angular dev server should not be used for prod serving. Build a container image with the angular prod build to benefit from much increased performance.

-- Thomas
Source: StackOverflow