本文介绍了阿里云的ALB Ingress Controller在过去半年中的升级和功能改进,包括更便捷的配置切换、更智能的错误拦截校验、更全面的容灾部署场景等。文章详细描述了新功能的实现和使用方法,并总结了ALB Ingress Controller在云原生领域的发展状况和后续规划。
包括支持AScript自定义编程脚本、慢启动、连接优雅中断、配置校验和容灾部署等高级功能,提升了用户体验和系统的稳定性。
介绍了ingress2Albconfig工具如何帮助用户将现有Nginx Ingress配置转换为ALB Ingress配置,以及该工具的使用方法和注意事项。
通过Webhook服务进行配置校验,能够尽早拦截错误配置,减少资源创建尝试和集群状态混乱,提高系统安全性和稳定性。
总结了ALB Ingress Controller的发展成果,并介绍了未来的产品规划和迭代方向。
ALB Ingress Controller立足用户需求,全面升级:更便捷的配置切换,更智能的错误拦截校验,更全面的容灾部署场景,持续提升用户体验。在过去半年中,ALB Ingress Controller立足用户需求,推出了一系列高级产品特性,致力于为用户提供更丰富的产品功能,更便捷的配置切换,更智能的错误拦截校验,更全面的容灾部署场景,持续提升用户体验,为用户业务保驾护航:
可编程脚本AScript是阿里云应用型负载均衡ALB (Application Load Balancer) 推出的突出灵活性和功能性的脚本语言,使得ALB实例能够突破传统负载均衡的局限,以自定义脚本的方式精确地控制和调整流量管理策略。
AScript支持自定义规则的执行,这些规则在处理客户端请求的不同阶段自动触发,确保实现高度自定义化的流量管理。无论是内容交付、安全性增强,还是性能优化,AScript都能灵活应对,实现负载均衡的智能化和个性化。新版本ALB Ingress Controller支持在Albconfig上配置AScript脚本,从而实现精细的业务管理,助您在复杂多变的业务环境中持续优化服务性能和用户体验。要使用AScript自定义编程脚本,您可以按照以下流程配置:
在ascript_configmap.yaml文件中创建AScript脚本对应的ConfigMap资源
apiVersion: v1
kind: ConfigMap
metadata:
name: ascript-rule
namespace: default
data:
scriptContent: |
if match($remote_addr, '127.0.0.1|10.0.0.1') {
add_rsp_header('X-IPBLOCK-DEBUG', 'hit')
exit(403)
}
- 在Albconfig yaml监听配置中配置AScript脚本需要配置的位置及相关参数
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: default
spec:
config:
name: xiaosha-alb-test-1
addressType: Intranet
listeners:
- port: 80
protocol: HTTP
aScriptConfig:
- aScriptName: ascript-rule
enabled: true
position: RequestFoot
configMapNamespace: default
extAttributeEnabled: true
extAttributes:
- attributeKey: EsDebug
attributeValue: test1
更多AScript 相关文档参考:
什么是可编程脚本AScript_负载均衡(SLB)-阿里云帮助中心:https://help.aliyun.com/zh/slb/application-load-balancer/user-guide/programmable-script/
AScript场景示例_负载均衡(SLB)-阿里云帮助中心:https://help.aliyun.com/zh/slb/application-load-balancer/user-guide/ascript-common-scenarios
在新增Pod加入Service后端后,如果ALB Ingress立即将流量分配至新增Pod,可能会造成瞬时的CPU或内存高压,导致访问异常。通过使用慢启动,ALB Ingress可以逐步将流量转移至新增Pod,缓解突发流量造成的影响。配置示例如下:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/slow-start-enabled: "true"
alb.ingress.kubernetes.io/slow-start-duration: "100"
name: alb-ingress
spec:
ingressClassName: alb
rules:
- host: alb.ingress.alibaba.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: tea-svc
port:
number: 80
在Pod进入Terminating状态时,ALB Ingress会将Pod从后端移除。在这种情况下,Pod已建立的连接中可能还有进行中的请求。如果ALB Ingress立即关闭所有连接,可能造成业务出现错误。通过使用连接优雅中断能力,ALB Ingress可以在Pod被从后端移除后,在特定时间中保持连接的开启,保证业务在当前请求处理完成后平滑下线。连接优雅中断的具体工作模式如下:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/connection-drain-enabled: "true"
alb.ingress.kubernetes.io/connection-drain-timeout: "199"
name: alb-ingress
spec:
ingressClassName: alb
rules:
- host: alb.ingress.alibaba.com
http:
paths:
- path: /test
pathType: Prefix
backend:
service:
name: tea-svc
port:
number: 80
二、更便捷的配置切换(ingress2Albconfig)
随着ALB Ingress功能不断完善,在Ingress场景中提供了丰富多样的特性,且作为一项全托管服务,ALB Ingress不仅免去了用户的运维负担,还提供了强大的弹性能力,受到用户一致认可。但是因为Ingress配置在长期维护下已经相当复杂,将这些配置一一修改为ALB Ingress的描述复杂度较高,所产生的工作量导致不得不放弃使用ALB Ingress。
基于这部分使用诉求,ALB Ingress团队推出一款小工具来帮助配置快速转换,无论是运维还是开发团队,都可以通过工具将现有Nginx Ingress配置转换为ALB Ingress配置,同时可以在不影响现有流量的情况下,灰度到ALB Ingress当中,其整体过程类似于下图:
通过DNS的方式,来将流量灰度到ALB上,可以确保流量正常的情况下具备恢复和容灾能力,具体到转发工具上,目前推送了工具镜像到官方仓库中,用户可以使用如下的Job来进行一次性转换工作,也可以以工具容器的形态长期运行,在功能进一步完善后会以更加通用的方式进行工具发布。
apiVersion: batch/v1
kind: Job
metadata:
name: ingress2albconfig
namespace: default
spec:
template:
spec:
containers:
- name: ingress2albconfig
image: registry.cn-hangzhou.aliyuncs.com/acs/ingress2albconfig:latest
command: ["/bin/ingress2albconfig", "print"]
restartPolicy: Never
serviceAccount: ingress2albconfig
serviceAccountName: ingress2albconfig
backoffLimit: 4
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:ingress2albconfig
rules:
- apiGroups:
- networking.k8s.io
resources:
- ingresses
- ingressclasses
verbs:
- get
- list
- watch
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: ingress2albconfig
namespace: default
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: system:ingress2albconfig
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:ingress2albconfig
subjects:
- kind: ServiceAccount
name: ingress2albconfig
namespace: default
在上述一次性任务中,使用了官方镜像的print指令,因为是在集群内部使用,所以需要配合授权RBAC使用,在示例中开启了对全部ingress资源的读权限,生成的资源会和原始资源在同一个Namespace,转换后配置的对应Name以from_为前缀表示。apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
creationTimestamp: null
name: from_nginx
spec:
config:
accessLogConfig: {}
edition: Standard
name: from_nginx
tags:
- key: converted/ingress2albconfig
value: "true"
zoneMappings:
- vSwitchId: vsw-xxx #替换为VPC中的虚拟交换机ID
- vSwitchId: vsw-xxx #替换为VPC中的虚拟交换机ID
listeners:
- port: 80
protocol: HTTP
---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
creationTimestamp: null
name: from_nginx
spec:
controller: ingress.k8s.alibabacloud/alb
parameters:
apiGroup: alibabacloud.com
kind: AlbConfig
name: from_nginx
scope: null
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80}]'
creationTimestamp: null
name: from_ingress1
namespace: default
spec:
ingressClassName: from_nginx
rules:
- http:
paths:
- backend:
service:
name: nginx-svc-g1msr
port:
number: 80
path: /
pathType: Prefix
status:
loadBalancer: {}
在上述生成资源中,并不能直接使用,需要填写对应VPC中的虚拟交换机ID,这是因为ALB的使用需要依赖底层可用区并使用交换机上IP来提供服务,需要在使用过程中进行符合预期的网络规划。目前ingress2Albconfig工具还处于早期阶段,后续会不断迭代,补充更多转换功能。如您在使用中发现还未支持的功能,欢迎联系我们提供反馈,我们会在之后的版本中优先实现对应功能。