How to forward traffic from domain in route53 to a pod using nginx ingress?

4/16/2019

I deployed grafana using helm and now it is running in pod. I can access it if I proxy port 3000 to my laptop. Im trying to point a domain grafana.something.com to that pod so I can access it externally. I have a domain in route53 that I can attach to a loadbalancer (Application Load Balancer, Network Load Balancer, Classic Load Balancer). That load balancer can forward traffic from port 80 to port 80 to a group of nodes (Let's leave port 443 for later). I'm really struggling with setting this up. Im sure there is something missing but I don't know what.

Basic diagram would look like this I imagine.

Internet
↓↓
Domain in route53 (grafana.something.com)
↓↓
Loadbalancer 80 to 80 (Application Load Balancer, Network Load Balancer, Classic Load Balancer) I guess that LB would forward traffic to port 80 to the below Ingress Controllers (Created when Grafana was deployed using Helm)
↓↓
Group of EKS worker nodes
↓↓
Ingress resource ?????
↓↓
Ingress Controllers - Created when Grafana was deployed using Helm in namespace test.

kubectl get svc grafana -n test

grafana Type:ClusterIP ClusterIP:10.x.x.x Port:80/TCP

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 
  labels:
    app: grafana
    chart: grafana-
    heritage: Tiller
    release: grafana-release
  name: grafana
  namespace: test
  resourceVersion: "xxxx"
  selfLink: 
  uid: 
spec:
  clusterIP: 10.x.x.x
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 3000
  selector:
    app: grafana
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

↓↓
Pod Grafana is listening on port 3000. I can access it successfully after proxying to my laptop port 3000.

-- tr53
amazon-route53
amazon-web-services
grafana
kubernetes
nginx

1 Answer

4/16/2019

Given that it seems you don't have an Ingress Controller installed, if you have the aws cloud-provider configured in your K8S cluster you can follow this guide to install the Nginx Ingress controller using Helm.

By the end of the guide you should have a load balancer created for your ingress controller, point your Route53 record to it and create an Ingress that uses your grafana service. Example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/app-root: /
    nginx.ingress.kubernetes.io/enable-access-log: "true"
  name: grafana-ingress
  namespace: test
spec:
  rules:
  - host: grafana.something.com
    http:
      paths:
      - backend:
          serviceName: grafana
          servicePort: 80
        path: /

The final traffic path would be:

Route53 -> ELB -> Ingress -> Service -> Pods
-- Esteban Garcia
Source: StackOverflow