# kubernetes-sigs/aws-load-balancer-controller architecture

> Architecture diagram of the GitHub repository kubernetes-sigs/aws-load-balancer-controller, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kubernetes-sigs/aws-load-balancer-controller
- Repository: https://github.com/kubernetes-sigs/aws-load-balancer-controller

## Overview

##### Main Components

a. Kubernetes Cluster Components:
- AWS Load Balancer Controller Pod
- Kubernetes API Server
- Webhook Server (shown in /webhooks directory)
- Custom Resource Definitions (shown in /apis directory)
- Service and Ingress Resources

b. AWS Components:
- Application Load Balancer (ALB)
- Network Load Balancer (NLB)
- Target Groups
- Security Groups
- AWS IAM (for permissions)

##### Controller Architecture Layers (based on the /pkg directory)

a. Core Controller Components:
- Ingress Controller (/controllers/ingress)
- Service Controller (/controllers/service)
- TargetGroupBinding Controller (/controllers/elbv2)

b. Supporting Systems:
- Webhook System (/webhooks)
- Metrics Collection (/pkg/metrics)
- AWS Service Clients (/pkg/aws)
- Networking Management (/pkg/networking)

##### Interaction Flows to Illustrate

a. Control Flow:
- Kubernetes API Server → Controller (Watch/List resources)
- Controller → AWS API (Create/Update load balancers)
- Controller → Webhook Server (Validate/Mutate resources)

b. Data Flow:
- External Traffic → Load Balancer → Kubernetes Services
- Load Balancer → Target Groups → Pods

##### Design Elements

Use the following visual elements:
- Rectangles: For main components
- Blue: Kubernetes components
- Orange: AWS components
- Green: Controller components
- Gray: Supporting infrastructure

##### Key Relationships

a. Controller Interactions:
- Controller → AWS APIs
- ELBv2 API (Load Balancers)
- EC2 API (Security Groups)
- ACM (Certificates)
- WAF (Web Application Firewall)

b. Resource Management:
- Controller
- Ingress → ALB
- Service → NLB
- TargetGroupBinding → Target Groups

##### Implementation Details

Following subsystems:
- Resource Reconciliation Loop
- AWS Service Clients
- Security Group Management
- Certificate Management
- Health Checking
- Metrics Collection

##### Deployment Context

Include:
- Kubernetes Cluster Boundary
- AWS VPC Boundary
- Internet Gateway
- IAM Roles and Policies

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Define styles
    classDef k8s fill:#326CE5,color:white
    classDef aws fill:#FF9900,color:black
    classDef controller fill:#68BC71,color:white
    classDef support fill:#666666,color:white
    classDef storage fill:#326CE5,color:white,stroke-width:2px

    %% Main components
    API[Kubernetes API Server]:::k8s
    WH[Webhook Server]:::k8s
    CTRL[AWS Load Balancer Controller]:::controller
    ALB[Application Load Balancer]:::aws
    NLB[Network Load Balancer]:::aws
    TG[Target Groups]:::aws
    SG[Security Groups]:::aws
    IAM[AWS IAM]:::aws

    %% Controller Components
    subgraph Controllers
        IC[Ingress Controller]:::controller
        SC[Service Controller]:::controller
        TGC[TargetGroupBinding Controller]:::controller
    end

    subgraph AWS_Services
        ELBV2[ELBv2 API]:::aws
        EC2[EC2 API]:::aws
        ACM[Certificate Manager]:::aws
        WAF[Web Application Firewall]:::aws
    end

    subgraph Supporting_Systems
        METRICS[Metrics Collection]:::support
        NET[Networking Management]:::support
        AWS_CLIENT[AWS Client Layer]:::support
    end

    subgraph Resource_Managers
        LBM[Load Balancer Manager]:::controller
        TGM[Target Group Manager]:::controller
        SGM[Security Group Manager]:::controller
    end

    %% Relationships
    API --> CTRL
    CTRL --> WH
    IC --> ELBV2
    SC --> ELBV2
    TGC --> TG
    ELBV2 --> ALB
    ELBV2 --> NLB
    EC2 --> SG
    
    CTRL --> AWS_CLIENT
    AWS_CLIENT --> AWS_Services
    
    IC --> LBM
    SC --> LBM
    TGC --> TGM
    SGM --> SG

    %% Click events
    click IC "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/controllers/ingress/group_controller.go"
    click SC "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/controllers/service/service_controller.go"
    click TGC "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/controllers/elbv2/targetgroupbinding_controller.go"
    click ELBV2 "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/pkg/aws/services/elbv2.go"
    click EC2 "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/pkg/aws/services/ec2.go"
    click ACM "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/pkg/aws/services/acm.go"
    click WAF "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/pkg/aws/services/wafv2.go"
    click WH "https://github.com/kubernetes-sigs/aws-load-balancer-controller/tree/main/webhooks/"
    click METRICS "https://github.com/kubernetes-sigs/aws-load-balancer-controller/tree/main/pkg/metrics/"
    click NET "https://github.com/kubernetes-sigs/aws-load-balancer-controller/tree/main/pkg/networking/"
    click AWS_CLIENT "https://github.com/kubernetes-sigs/aws-load-balancer-controller/tree/main/pkg/aws/"
    click LBM "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/pkg/deploy/elbv2/load_balancer_manager.go"
    click TGM "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/pkg/deploy/elbv2/target_group_manager.go"
    click SGM "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/pkg/deploy/ec2/security_group_manager.go"
    click CTRL "https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/main.go"

    %% Legend
    subgraph Legend
        K8S[Kubernetes Components]:::k8s
        AWS[AWS Components]:::aws
        CONT[Controller Components]:::controller
        SUPP[Supporting Systems]:::support
    end
```
