You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为AKS集群启用匿名访问?千级用户访问配置失败求助

AKS集群匿名访问配置(支持1000+并发用户)

要搞定AKS的匿名访问并支撑上千用户,光改ClusterRole和ClusterRoleBinding不够,得把API Server的匿名开关打开,再配好权限,最后做性能调优,一步步来:

1. 开启AKS API Server的匿名访问

AKS默认禁用匿名访问,这是核心前提,之前没开的话RBAC配置再对也没用。用Azure CLI更新集群配置:

az aks update --name <你的集群名称> --resource-group <你的资源组名称> --enable-anonymous-auth

更新完成后,确认API Server启动参数包含--anonymous-auth=true即可。

2. 配置正确的RBAC权限

给匿名用户分配适配业务的权限,比如只读需求的话,按以下步骤配置:

创建只读ClusterRole

保存为anonymous-read-only-role.yaml:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: anonymous-read-only
rules:
# 核心API组资源权限
- apiGroups: [""]
  resources: ["pods", "services", "nodes", "namespaces", "configmaps"]
  verbs: ["get", "list", "watch"]
# 应用层资源权限
- apiGroups: ["apps"]
  resources: ["deployments", "statefulsets", "daemonsets"]
  verbs: ["get", "list", "watch"]
# 按需添加其他API组,比如networking.k8s.io的ingress等

创建ClusterRoleBinding绑定匿名用户

保存为anonymous-read-only-binding.yaml:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: anonymous-read-only-binding
subjects:
# 匹配单个匿名用户
- kind: User
  name: system:anonymous
  apiGroup: rbac.authorization.k8s.io
# 匹配所有未认证用户组(包含匿名用户)
- kind: Group
  name: system:unauthenticated
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: anonymous-read-only
  apiGroup: rbac.authorization.k8s.io

应用配置:

kubectl apply -f anonymous-read-only-role.yaml -f anonymous-read-only-binding.yaml

验证权限:

kubectl auth can-i list pods --as=system:anonymous

返回yes说明权限配置生效。

3. 性能调优支撑1000+用户

上千并发访问需要调整API Server的资源和限流参数:

  • 升级控制平面节点规格:把AKS控制平面节点换成Standard_D4s_v3或更高规格的VM,提升处理能力。
  • 调整API Server限流参数:通过Azure CLI提高并发请求上限:
az aks update --name <集群名> --resource-group <资源组> \
  --api-server-args max-requests-inflight=2000 \
  --api-server-args max-mutating-requests-inflight=1000
  • 优化缓存策略:AKS默认开启部分API缓存,可根据实际负载调整缓存过期参数,减少etcd查询压力。

4. 测试验证

用未认证请求测试API:

curl https://<你的AKS API地址>/api/v1/pods

能正常返回Pod列表,说明匿名访问配置成功。

内容的提问来源于stack exchange,提问作者Arockia Daniel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 06:27:33