What is AWS Ingress Annotations?

Featured image

image reference link



Overview

Learn about AWS Load Balancer Controller Ingress Annotations and how they manage traffic routing to Kubernetes services using Application Load Balancers (ALB). These annotations provide a powerful way to customize and configure how external traffic is routed to your applications running on EKS or other Kubernetes deployments on AWS.


What is Ingress Annotations?

In AWS, the AWS load balancer controller configures and manages the behavior of the Application Load Balancer (ALB) that routes traffic to the Kubernetes service using annotations for incoming resources.

Annotations allow you to specify settings such as SSL, routing behavior, and security groups directly within the Kubernetes Ingress resource.

How Load Balancer Controller Works

Ingress Groups

Ingress Group Name Settings

Ingress Group Ranking

Ingress Group Example

In the example below, two ingress resources share a group called my-shared-group, so one ALB processes the request.

# Ingress for Service A
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: service-a-ingress
  annotations:
    alb.ingress.kubernetes.io/group.name: "my-shared-group"
    alb.ingress.kubernetes.io/group.order: "10"
spec:
  rules:
    - host: "service-a.example.com"
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: service-a
                port:
                  number: 80

# Ingress for Service B
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: service-b-ingress
  annotations:
    alb.ingress.kubernetes.io/group.name: "my-shared-group"
    alb.ingress.kubernetes.io/group.order: "20"
spec:
  rules:
    - host: "service-b.example.com"
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: service-b
                port:
                  number: 80



Ingress Traffic Listening

listen-ports: Specify ports for ALB

[{"HTTP": 80}, {"HTTPS": 443}]

ssl-redirect: Enable SSL redirection

'443'

ip-address-type: IPv4 or dualstack support

ipv4 or dualstack

waf-acl-id: Associate AWS WAF WebACL

arn:aws:wafv2:region:account:webacl/my-web-acl/id

listen-ports

ssl-redirect

ip-address-type

waf-acl-id

customer-owned-ipv4-pool

Full Example

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: secure-app-ingress
  annotations:
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
    alb.ingress.kubernetes.io/ssl-redirect: '443'
    alb.ingress.kubernetes.io/certificate-arn: 'arn:aws:acm:region:account:certificate/cert-id'
    alb.ingress.kubernetes.io/ip-address-type: 'dualstack'
    alb.ingress.kubernetes.io/waf-acl-id: 'arn:aws:wafv2:region:account:webacl/my-web-acl/id'
spec:
  ingressClassName: alb
  rules:
    - host: secure-app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: secure-app-service
                port:
                  number: 80



Ingress Traffic Routing

load-balancer-name: Specify custom ALB name

my-awesome-alb

target-type: Routing to instances or IP addresses

instance or ip

backend-protocol: Protocol for backend traffic

HTTP, HTTPS

target-group-attributes: Target group configuration

stickiness.enabled=true

load-balancer-name

target-type

target-node-labels

backend-protocol

backend-protocol-version

target-group-attributes

health-check-* annotations

actions.${action-name} and conditions.${conditions-name}

Here’s an example showing how to use advanced actions and conditions:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: default
  name: ingress
  annotations:
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/actions.rule-path1: >
      {"type":"fixed-response","fixedResponseConfig":{"contentType":"text/plain","statusCode":"200","messageBody":"Host is www.example.com OR anno.example.com"}}
    alb.ingress.kubernetes.io/conditions.rule-path1: >
      [{"field":"host-header","hostHeaderConfig":{"values":["anno.example.com"]}}]
    # More actions and conditions...
spec:
  ingressClassName: alb
  rules:
    - host: www.example.com
      http:
        paths:
          - path: /path1
            pathType: Exact
            backend:
              service:
                name: rule-path1
                port:
                  name: use-annotation
          # More paths...

These advanced rules allow for complex traffic routing scenarios including:



Ingress Access Control

Scheme: Define ALB as internal or internet-facing

alb.ingress.kubernetes.io/scheme

CIDR: Restrict IP ranges

alb.ingress.kubernetes.io/inbound-cidrs

Security Groups: Specify security groups

alb.ingress.kubernetes.io/security-groups

Subnet Discovery: Specify subnets for ALB

alb.ingress.kubernetes.io/subnets

Auth: Configure authentication

alb.ingress.kubernetes.io/auth-*

scheme

inbound-cidrs

security-groups

manage-backend-security-group-rules

subnets

The AWS Load Balancer Controller supports various authentication mechanisms through annotations:

OIDC Authentication
alb.ingress.kubernetes.io/auth-type: oidc
alb.ingress.kubernetes.io/auth-idp-oidc-config: '{"issuer":"https://example.com","secretName":"oidc-secret"}'
alb.ingress.kubernetes.io/auth-on-unauthenticated-request: authenticate
alb.ingress.kubernetes.io/auth-scope: openid
Cognito Authentication
alb.ingress.kubernetes.io/auth-type: cognito
alb.ingress.kubernetes.io/auth-idp-cognito: '{"userPoolARN":"arn:aws:cognito-idp:region:account:userpool/id","userPoolClientID":"client-id"}'
alb.ingress.kubernetes.io/auth-on-unauthenticated-request: authenticate
alb.ingress.kubernetes.io/auth-scope: openid

These authentication mechanisms allow you to secure your applications by ensuring users are authenticated before accessing them.

Example: Securing an Internal Application

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: secure-internal-app
  annotations:
    alb.ingress.kubernetes.io/scheme: internal
    alb.ingress.kubernetes.io/inbound-cidrs: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
    alb.ingress.kubernetes.io/security-groups: sg-private-apps
    alb.ingress.kubernetes.io/auth-type: cognito
    alb.ingress.kubernetes.io/auth-idp-cognito: '{"userPoolARN":"arn:aws:cognito-idp:region:account:userpool/id","userPoolClientID":"client-id"}'
spec:
  ingressClassName: alb
  rules:
    - host: internal-app.company.local
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: internal-app
                port:
                  number: 80

This example creates an internal ALB that:



SSL/TLS Configuration

certificate-arn: ARN of ACM certificate

arn:aws:acm:region:account:certificate/cert-id

ssl-policy: Security policy for TLS

ELBSecurityPolicy-TLS-1-2-2017-01

ssl-redirect: Redirect HTTP to HTTPS

'443'

certificate-arn

ssl-policy

Example: Configuring HTTPS with Multiple Certificates

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: multi-domain-app
  annotations:
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
    alb.ingress.kubernetes.io/certificate-arn: >-
      arn:aws:acm:region:account:certificate/cert1,
      arn:aws:acm:region:account:certificate/cert2
    alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-FS-2018-06
    alb.ingress.kubernetes.io/ssl-redirect: '443'
spec:
  ingressClassName: alb
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: app-service
                port:
                  number: 80
    - host: app.another-domain.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: app-service
                port:
                  number: 80

This example:



Advanced Features and Use Cases

Cross-Zone Load Balancing: Even distribution across AZs

load_balancing.cross_zone.enabled=true

Idle Timeout: Connection idle time

idle_timeout.timeout_seconds=60

HTTP/2 Support: Enable HTTP/2 protocol

routing.http2.enabled=true

Access Logging: Log traffic to S3

access_logs.s3.enabled=true

Cross-Zone Load Balancing

Idle Timeout

HTTP/2 Support

Access Logging


Best Practices


1. Ingress Groups: - Use meaningful group names that reflect the application or team
- Set appropriate order values (10, 20, 30) with gaps to allow for future insertions
- Share ALBs efficiently by grouping related services
- Keep group membership stable to avoid unnecessary ALB creation/deletion

2. Security: - Use appropriate scheme (internal for private services, internet-facing for public)
- Implement CIDR restrictions to limit access to trusted IP ranges
- Configure security groups with least privilege access
- Enable access logging for security monitoring
- Use WAF for additional layer of protection
- Use strong SSL policies and redirect HTTP to HTTPS

3. Routing: - Choose the correct target type (instance vs. ip) based on your network setup
- Set proper protocols matching your application's expectations
- Configure appropriate health checks
- Define clear conditions for complex routing scenarios
- Use sticky sessions when needed for stateful applications

4. Performance: - Enable HTTP/2 for improved client performance
- Configure appropriate idle timeout values
- Use cross-zone load balancing for even distribution
- Monitor ALB metrics in CloudWatch
- Set appropriate deregistration delay to allow in-flight requests to complete

5. Cost Optimization: - Share ALBs using ingress groups to reduce the number of load balancers
- Use internal ALBs for services that don't need public access
- Consider using NLB for TCP/UDP workloads rather than ALB
- Monitor and clean up unused resources


Troubleshooting Tips


1. ALB Not Created: - Check controller logs for errors
- Verify IAM permissions for the controller
- Ensure subnet discovery tags are correct

2. Traffic Not Reaching Service: - Verify target group health checks are passing
- Check security group rules allow traffic flow
- Confirm service is running and listening on correct port

3. SSL/TLS Issues: - Verify certificate ARN is correct and in the same region
- Ensure certificate covers the domain in your ingress host rule
- Check for certificate expiration

4. Authentication Problems: - Verify configuration of Cognito/OIDC settings
- Check for proper secret configuration
- Look for errors in ALB access logs



Reference