How do you access a service of type external name with Ingress

Issue

This Content is from Stack Overflow. Question asked by Rodrigo Acosta Segui

I created an ingress and a service of the external name type to perform a url pointer from http://api.k8s.dev.pl.com.br/event-engine-api-service to an ec2 with public dns ec2- 52-35-88-17.us-west-2.compute.amazonaws.com

apiVersion: v1
kind: Service
metadata:
  labels:
    app: event-engine-api-service
    release: event-engine-api-service
  name: event-engine-api-service
  namespace: default
spec:
  type: ExternalName
  externalName: ec2-52-35-88-17.us-west-2.compute.amazonaws.com
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: event-engine-api-service
  namespace: default
spec:
  rules:
  - host: api.k8s.dev.pl.com.br
    http:
      paths:
      - backend:
          service:
            name: event-engine-api-service
            port:
              name: http
        path: /event-engine-api-service(/|$)(.*)
        pathType: ImplementationSpecific

RESULT : ERROR IN BROWSER NAVIGATOR 502 Bad Gateway nginx



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?