AWS ALB Ingress Controller and ingress resource for python app

10/8/2020

I have created python app following this link https://kubernetes.io/blog/2019/07/23/get-started-with-kubernetes-using-python/. I want to configure AWS ALB Ingress Controller/nginx controller and ingress resource but I am unable to understand the file. I don't have a domain using Kops on ec2-instance, want to configure it without any domain. Any help would be appreciated.

deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-python
spec:
  selector:
    matchLabels:
      app: hello-python
  template:
    metadata:
      labels:
        app: hello-python
    spec:
      containers:
      - name: hello-python
        image: hello-python:latest
        ports:
        - containerPort: 5000

service

apiVersion: v1
kind: Service
metadata:
  name: hello-python-service
spec:
  selector:
    app: hello-python
  type: NodePort
  ports:
    - nodePort: 30010
      port: 6000
      targetPort: 5000
-- user13870897
amazon-web-services
aws-alb
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

10/8/2020

An Ingress binds a Service like hello-python-service above to an ALB through the nginx ingress controller.

It does so by mapping a virtual host to your service so that nginx knows how to route requests.

example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: python-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: ingress-controller-nginx
    nginx.ingress.kubernetes.io/default-backend: hello-python-service
    nginx.ingress.kubernetes.io/rewrite-target: /$1

spec:
  rules:
    - host: python.trash.net
      http:
        paths:
          - path: /?(.*)
            backend:
              serviceName: hello-python-service
              servicePort: 6000

would generate a resource of class Ingress like the below:

python-ingress   python.trash.net   internal-0358a08f01385b2812-331143124.us-east-2.elb.amazonaws.com   80      10s

issuing a curl request like this:

curl -H "Host: python.trash.net" http://internal-0358a08f01385b2812-331143124.us-east-2.elb.amazonaws.com

should get you a response from your hello python app.

This obviously depends on you having the nginx ingress controller deployed and configured in your EKS cluster.

The key takeaway for an ingress is this: It replaces the need for a dedicated service of type LoadBalancer to provide external access to your service. Instead, Ingress maps traffic from outside the cluster to services in the cluster through a virtual host that is configured in the Ingress' manifest file.

-- mcfinnigan
Source: StackOverflow