0

Versions and references are noted below.

I am attempting to migrate my Angular client application and my Node/Express API from a Heroku virtualized server to DigitalOcean's Managed Kubernetes (DOKS). Largely following the Ingress Tutorial (see References, below), I have successfully:

  • Used Docker to containerize both the Angular and the API,
  • Setup a Kubernetes cluster and container registry on DOKS,
  • Setup nginx-ingress,
  • Setup jetstack/cert-manager and Let's Encrypt,
  • Configured my domain name register and DOKS DNS,
  • Deployed both the Angular and API to pods,
  • Connected to the API from the Internet.

The pertinent YAML configuration files are attached below (see Configurations, below). I'd be glad to add others if it would help.

Where I have failed is connecting to the Angular from the Internet. I receive an HTTP 502 Bad Gateway when connecting.

To ensure my Angular code was not causing the problem, I have created a default Angular app, following the Default Angular Tutorial (see References).

I followed Troubleshooting Deployments (see References) and determined the following:

  • Using kubectl port-forward, I am able to connect to the Angular app's pod at port 4200,
  • Using kubectl port-forward, I am able to connect to the Angular app's Cluster IP service at port 80,
  • I am not able to connect to the Angular app's service via Ingress (502 Bad Gateway),
  • Reviewing the ingress logs using the ingress-nginx plugin to kubectl, I was able to find an error code.

The error code in the ingress log is:

2021/04/12 06:08:43 [error] 423#423: *1158356 connect() failed (111: Connection refused) while connecting to upstream, client: XXX.XXX.XXX.XXX, server: pvg.example.com, request: "GET / HTTP/1.1", upstream: "http://XXX.XXX.XXX.XXX:4200/", host: "pvg.example.com"

This is where I am stuck. I would be grateful for any insights from this expert community.

Thank you!

Disclaimer: I have also asked this question on DigitalOcean's Community website with no responses over the last week (see References, below). When answered, I will link the two together.

Configurations

Configuration for Service and Deployment of Angular:

---
apiVersion: v1
kind: Service
metadata:
  name: my-app-cip
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: 4200
  selector:
    app: my-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: nginx
        image: registry.digitalocean.com/XXXXXXXX/my-app:0.1.0
        ports:
        - containerPort: 4200
          protocol: TCP

Configuration for Ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
  - hosts:
    - api.example.com    # This is working
    - pvg.example.com    # This is NOT working
    secretName: hello-kubernetes-tls
  rules:
  - host: "api.example.com"  # This is working
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: my-api-cip
            port:
              number: 80
  - host: "pvg.example.com"  # This is NOT working
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: my-app-cip
            port:
              number: 80

Versions

  • node.js 10.19.0
  • npm 7.7.6
  • yarn 1.22.10
  • ng 11.2.2
  • docker 19.03.8
  • kubectl 1.20.1
  • doctl 1.57.0
  • kubernetes 1.20.2-do.0
  • helm 3.5.3
  • nginx controller 0.45.0
  • jetstack 1.3.0

References

Ingress Tutorial

Default Angular Tutorial:

Troubleshooting Deployments

Question as asked on DigitalOcean Community website:

EDIT: Fixed markdown mistakes; added comment to YAML for clarification; fixed typo in Ingress YAML file.

MarkWilx
  • 21
  • 8
  • Service is created with name "my-app-cip" and in Ingress it is referred as "my-app". Is it typo? If it is not typo then this could be the issue. – Kiruba Apr 12 '21 at 09:55
  • Thanks for catching it. Unfortunately, I just typo’d the YAML file. I had previously called both the Deployment and Service by the same name (per the example I followed), but I changed them so I could better debug. The name was correct on my dev machine (and I fixed the writeup above). Regardless, I tested in case you were right! If I set the path name to something that does not exist (I tried “my-app-trash”), I get a 503 Service Temporarily Unavailable error. When I return it to the correct value (my-app-cip), I get a 502 Bad Gateway error. Thank you for taking a look. – MarkWilx Apr 12 '21 at 11:21
  • Did @Kiruba advice helped ? – Malgorzata Apr 20 '21 at 07:13
  • No, unfortunately, I'd already solved the problem that @Kiruba found. I have an open ticket with DigitalOcean on this issue. We've been going back-and-forth with lots of tests for almost two weeks. When I have a solution, I'll post it here. – MarkWilx Apr 28 '21 at 16:47

0 Answers0