Kubernetes: AWS Load Balancer Controller (ALB Ingress controller) and cross namespaces

February 12, 2021 - Last updated: February 12, 2021

Assuming you have deployed AWS Load Balancer Controller, the following steps are how to configure one ALB to expose all your services, also services cross namespaces.

Default configuration for the ALB "dev" with the following features:

  • HTTP redirect to HTTPs.
  • SSL termination, with ACM certificate provide from AWS.
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: dev
  namespace: alb-ingress-controller
  annotations:
    kubernetes.io/ingress.class: "alb"
    alb.ingress.kubernetes.io/group.name: "dev"
    alb.ingress.kubernetes.io/certificate-arn: "arn:aws:acm:....................."
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
    alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
spec:
  rules:
    - http:
        paths:
          - path: /*
            backend:
              serviceName: ssl-redirect
              servicePort: use-annotation

Ingress for my applications, that use the ALB "dev".

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: echo
  namespace: tools
  annotations:
    kubernetes.io/ingress.class: "alb"
    alb.ingress.kubernetes.io/group.name: "dev"
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}]'
spec:
  rules:
    - host: echo.mydomain.com
      http:
        paths:
          - path: /*
            backend:
              serviceName: echo
              servicePort: 80

Service for my application, remember to set the service type as NodePort.

---
apiVersion: v1
kind: Service
metadata:
  name: echo
  namespace: tools
spec:
  type: NodePort
  selector:
    app: echo
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP

Related posts