计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
aws-elb【效率与协作】"Configures Elastic Load Balancing (ALB, NLB, Classic) for distributing" traffic across instances with health checks, SSL termination, and cross-AZ failover.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: aws-elb compatibility: opencode completeness: 95 content-types:
Distribute traffic across EC2 instances with health checks, SSL/TLS termination, and automatic failover for high availability and scalability.
Use ELB when:
Avoid ELB when:
Primary Purpose: Distribute incoming application traffic across multiple targets with SSL termination, health checks, and automatic failover.
Common Use Cases:
AWSTemplateFormatVersion: '2010-09-09'
Resources:
# Application Load Balancer
ApplicationLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: web-alb
Type: application
Scheme: internet-facing
IpAddressType: ipv4
Subnets:
- subnet-0123456789abcdef0 # Public subnet AZ1
- subnet-0123456789abcdef1 # Public subnet AZ2
- subnet-0123456789abcdef2 # Public subnet AZ3
SecurityGroups:
- sg-0123456789abcdef0 # ALB security group
Tags:
- Key: Name
Value: web-alb
# Target Group
WebTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: web-tg
Port: 8080
Protocol: HTTP
VpcId: vpc-0123456789abcdef0
HealthCheckEnabled: true
HealthCheckProtocol: HTTP
HealthCheckPath: /health
HealthCheckIntervalSeconds: 30
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
UnhealthyThresholdCount: 3
Matcher:
HttpCode: 200-299
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 30
- Key: stickiness.enabled
Value: 'false'
- Key: load_balancing.algorithm.type
Value: least_outstanding_requests
Tags:
- Key: Name
Value: web-tg
# HTTP Listener (redirect to HTTPS)
HTTPListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: redirect
RedirectConfig:
Protocol: HTTPS
Port: '443'
StatusCode: HTTP_301
LoadBalancerArn: !Ref ApplicationLoadBalancer
Port: 80
Protocol: HTTP
# HTTPS Listener
HTTPSListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
Certificates:
- CertificateArn: arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WebTargetGroup
LoadBalancerArn: !Ref ApplicationLoadBalancer
Port: 443
Protocol: HTTPS
SslPolicy: ELBSecurityPolicy-TLS-1-2-2017-01
# Host-Based Routing
HostBasedListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref WebTargetGroup
Conditions:
- Field: host-header
Values:
- example.com
- www.example.com
ListenerArn: !Ref HTTPSListener
Priority: 1
# Path-Based Routing
PathBasedListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref APITargetGroup
Conditions:
- Field: path-pattern
Values:
- /api/*
ListenerArn: !Ref HTTPSListener
Priority: 2
# API Target Group
APITargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: api-tg
Port: 8000
Protocol: HTTP
VpcId: vpc-0123456789abcdef0
HealthCheckPath: /api/health
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 60
- Key: load_balancing.algorithm.type
Value: least_outstanding_requests
# Register EC2 Instances (Alternative: Auto Scaling Group)
# Typically done via Auto Scaling Group with TargetGroupArNs property
# CloudWatch Alarms
ALBUnHealthyHostsAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: ALB-Unhealthy-Hosts
MetricName: UnHealthyHostCount
Namespace: AWS/ApplicationELB
Statistic: Average
Period: 300
EvaluationPeriods: 2
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: TargetGroup
Value: !GetAtt WebTargetGroup.TargetGroupFullName
- Name: LoadBalancer
Value: !GetAtt ApplicationLoadBalancer.LoadBalancerFullName
ALBHighLatencyAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: ALB-High-Latency
MetricName: TargetResponseTime
Namespace: AWS/ApplicationELB
Statistic: Average
Period: 300
EvaluationPeriods: 2
Threshold: 1.0 # 1 second
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: LoadBalancer
Value: !GetAtt ApplicationLoadBalancer.LoadBalancerFullName
ALBHTTPErrorsAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: ALB-HTTP-5xx-Errors
MetricName: HTTPCode_Target_5XX_Count
Namespace: AWS/ApplicationELB
Statistic: Sum
Period: 300
EvaluationPeriods: 2
Threshold: 10
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: LoadBalancer
Value: !GetAtt ApplicationLoadBalancer.LoadBalancerFullName
Outputs:
LoadBalancerDNS:
Value: !GetAtt ApplicationLoadBalancer.DNSName
Description: ALB DNS name
LoadBalancerArn:
Value: !Ref ApplicationLoadBalancer
Description: ALB ARN
TargetGroupArn:
Value: !Ref WebTargetGroup
Description: Target group ARN (for ASG)
Key Elements:
Resources:
# Network Load Balancer
HighPerformanceLB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: high-perf-nlb
Type: network
Scheme: internet-facing
IpAddressType: ipv4
Subnets:
- subnet-0123456789abcdef0
- subnet-0123456789abcdef1
- subnet-0123456789abcdef2
LoadBalancerAttributes:
- Key: load_balancing.cross_zone.enabled
Value: 'true'
Tags:
- Key: Name
Value: high-perf-nlb
# TCP Target Group
TCPTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: tcp-tg
Port: 9000
Protocol: TCP
VpcId: vpc-0123456789abcdef0
HealthCheckEnabled: true
HealthCheckProtocol: TCP
HealthCheckIntervalSeconds: 10
HealthyThresholdCount: 2
UnhealthyThresholdCount: 2
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 30
- Key: preserve_client_ip.enabled
Value: 'true'
# TCP Listener
TCPListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TCPTargetGroup
LoadBalancerArn: !Ref HighPerformanceLB
Port: 9000
Protocol: TCP
Key Elements:
Resources:
# Security group for ALB
ALBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: alb-sg
GroupDescription: Security group for ALB
VpcId: vpc-0123456789abcdef0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
Description: HTTP from anywhere
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
Description: HTTPS from anywhere
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
# Security group for targets (restrict to ALB)
TargetSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: target-sg
GroupDescription: Security group for ALB targets
VpcId: vpc-0123456789abcdef0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 8080
ToPort: 8080
SourceSecurityGroupId: !Ref ALBSecurityGroup
Description: App traffic from ALB
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
Key Elements:
ASG + ALB enables:
ALB + CloudWatch provides:
WAF + ALB provides:
Route 53 + ALB enables:
Problem: Failed instances still receive traffic; user-facing errors.
Solution:
Problem: In-flight requests dropped during instance termination.
Solution:
Problem: Session stickiness can cause uneven load; if target fails, session lost.
Solution:
Problem: AZ failure causes complete outage; no automatic failover.
Solution:
Problem: Weak SSL ciphers expose traffic to interception.
Solution:
Problem: Silent failures; no alerts when targets become unhealthy.
Solution:
| Category | Best Practice |
|---|---|
| Type | ALB for HTTP/HTTPS; NLB for extreme performance |
| Availability | Targets in 2+ AZs; health checks enabled |
| Security | SSL termination at LB; restrict target SGs to LB |
| Graceful Shutdown | Enable connection draining (deregistration delay) |
| Monitoring | CloudWatch alarms for health, latency, errors |
| Sessions | Use stateless design; session store for state |
| Skill | Purpose |
|---|---|
cncf-aws-ec2 | Target instances for load balancing |
cncf-aws-auto-scaling | Dynamic target registration via ASG |
cncf-aws-vpc | Load balancer and target networking |
cncf-aws-cloudwatch | Health and performance monitoring |
Assess Requirements — Understand the use case, scale, integration needs, and existing infrastructure. Checkpoint: Document requirements, constraints, and success criteria.
Design Architecture — Plan component interactions, data flow, and deployment strategy using cloud-native best practices. Checkpoint: Verify the architecture addresses all requirements and follows CNCF conventions.
Implement & Configure — Create manifests, configurations, and deployment scripts. Include resource limits, health checks, and observability hooks. Checkpoint: Validate all YAML against schema and test in a staging environment.
Deploy & Monitor — Apply manifests to the cluster, verify component health, and confirm observability is working. Checkpoint: Confirm all pods/services are running, probes passing, and metrics/alerts configured.
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.