【Azure K8S】演示修复因AKS密钥过期而导致创建服务不成功的问题(The provided client secret keys for app ****** are expired)

AKS,问题,密钥,client · 浏览次数 : 30

小编点评

**问题描述:** 在 Azure Kubernetes 服务中创建一个 Internal Load Balancer 服务,使用以下 YAML 内容: ```yaml interallb.yamlapiVersion: v1kind: Servicemetadata: name: ilb-myapp annotations: service.beta.kubernetes.io/azure-load-balancer-internal: \"true\"spec: type: LoadBalancer ports: - port: 80 selector: app: myappapply ``` 查看 service 状态,一直保持 pending。 **输出结果:** ``` NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEilb-myapp LoadBalancer 10.0.32.246 <pending> 80:30198/TCP 92mkubernetes ClusterIP 10.0.0.1 <none> 443/TCP 13h Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning UpdateLoadBalancerFailed 45m (x26 over 82m) service-controller (combined from similar events): Error updating load balancer with new hosts map[aks-vmss000002:{} aks-vmss000003:{} aks-vmss000006:{} aks-vmss000007:{}]: shouldUpdateLoadBalancer: failed to list managed load balancers: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 401, RawError: azure.BearerAuthorizer#WithAuthorization: Failed to refresh the Token for request to http://localhost:7788/*****: StatusCode=401 -- Original Error: adal: Refresh request failed. Status Code = '401'. Response body: {\"error\":\"invalid_client\",\"error_description\":\"AADSTS7000222: The provided client secret keys for app '********-****-****-****-************' are expired. Visit the Azure portal to create new keys for your app: https://aka.microsoft.com/zh-cn/azure/active-directory/develop/quickstart-create-client-secret}   ``` **问题解答:** 根据错误消息,app client secret 已经过期。要解决这个问题,需要更换新的 secret。操作步骤如下: 1. 在 Azure AD 中查找到对应的注册应用,并在注册应用中,重新生成新的Client Secret,复制保存新的Secret (用于第二步中)。 2. 使用 az aks update-credentials 命令,更新AKS集群中的密钥值(Secret Value) ``` az aks update-credentials --resource-group <resource group name> --name <AKS Cluster name> --reset-service-principal --service-principal <App Application ID> --client-secret <第一步中的Secret Value> ``` 当命令执行完成后,在此检查 Service 状态,不在是 Pending。而是分配了正确的 IP 地址。

正文

问题描述

在Azure Kubernetes 服务中,创建一个Internal Load Balancer服务,使用以下yaml内容:

internallb.yaml

apiVersion: v1
kind: Service
metadata:
  name: ilb-myapp
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: myapp

apply yaml

kubectl apply -f internallb.yaml

查看service状态,一直保持pending

kubectl get service

## 输出结果:
NAME               TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
ilb-myapp          LoadBalancer   10.0.32.246   <pending>     80:30198/TCP   92m
kubernetes         ClusterIP      10.0.0.1      <none>        443/TCP        13h

查看service日志

"error_description":"AADSTS7000222: The provided client secret keys for app '********-****-****-****-************' are expired

kubectl describe service  ilb-myapp 

##输出结果:
Events:
  Type     Reason                    Age                  From                  Message
  ----     ------                    ----                 ----                  -------
  Warning  UpdateLoadBalancerFailed  45m (x26 over 82m)   service-controller    (combined from similar events): Error updating load balancer with new hosts map[aks-vmss000002:{} aks-vmss000003:{} aks-vmss000006:{} aks-vmss000007:{}]: shouldUpdateLoadBalancer: failed to list managed load balancers: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 401, RawError: azure.BearerAuthorizer#WithAuthorization: Failed to refresh the Token for request to http://localhost:7788/*****: StatusCode=401 -- Original Error: adal: Refresh request failed. Status Code = '401'. Response body: {"error":"invalid_client","error_description":"AADSTS7000222: The provided client secret keys for app '********-****-****-****-************' are expired. Visit the Azure portal to create new keys for your app: https://aka.ms/NewClientSecret, or consider using certificate credentials for added security: https://aka.ms/certCreds.\r\nTrace ID: fa5035d2-1a6e-4b5a-85d0-910862a12501\r\nCorrelation ID: a184c126-96cb-42a9-8c4b-92869210e295\r\nTimestamp: 2023-05-31 02:33:46Z","error_codes":[7000222],"timestamp":"2023-05-31 02:33:46Z","trace_id":"fa5035d2-1a6e-4b5a-85d0-910862a12501","correlation_id":"a184c126-96cb-42a9-8c4b-92869210e295","error_uri":"https://login.chinacloudapi.cn/error?code=7000222"} 
  Normal   EnsuringLoadBalancer      37s (x25 over 95m)   service-controller    Ensuring load balancer
  Warning  ListLoadBalancers         37s (x152 over 91m)  azure-cloud-provider  (combined from similar events): Retriable: false, RetryAfter: 0s, HTTPStatusCode: 401, RawError: azure.BearerAuthorizer#WithAuthorization: Failed to refresh the Token for request to http://localhost:7788/*****: StatusCode=401 -- Original Error: adal: Refresh request failed. Status Code = '401'. Response body: {"error":"invalid_client","error_description":"AADSTS7000222: The provided client secret keys for app '********-****-****-****-************' are expired. Visit the Azure portal to create new keys for your app: https://aka.ms/NewClientSecret, or consider using certificate credentials for added security: https://aka.ms/certCreds.\r\nTrace ID: 277e6d9c-d663-4415-bff9-ef6610dc4f01\r\nCorrelation ID: 383589a0-2dd7-4c8e-a1a3-23a48ae8bd6d\r\nTimestamp: 2023-05-31 03:19:01Z","error_codes":[7000222],"timestamp":"2023-05-31 03:19:01Z","trace_id":"277e6d9c-d663-4415-bff9-ef6610dc4f01","correlation_id":"383589a0-2dd7-4c8e-a1a3-23a48ae8bd6d","error_uri":"https://login.chinacloudapi.cn/error?code=7000222"} 
 

 

问题解答

根据错误消息,已经得知是 app client secret 已经过期。那么要修复这个问题,就是更换新的 secret。操作步骤有两步:

第一步 :根据错误消息中的Application ID,在Azure AD中查找到对应的注册应用

在注册应用中,重新生成新的Client Secret,复制保存新的Secret(用于第二步中)

第二步 : 使用 az aks update-credentials 命令,更新AKS集群中的密钥值(Secret Value)

  az aks update-credentials --resource-group <resource group name>  --name <AKS Cluster name>  --reset-service-principal --service-principal <App Application ID>    --client-secret  <第一步中的Secret Value>

命令参考文档:

当命令执行完成后,在此检查 Service 状态,不在是Pending。而是分配了正确的IP地址

 

参考资料

故障排查:

使用服务主体凭据更新 AKS 群集 :https://docs.azure.cn/zh-cn/aks/update-credentials#update-aks-cluster-with-service-principal-credentials

与【Azure K8S】演示修复因AKS密钥过期而导致创建服务不成功的问题(The provided client secret keys for app ****** are expired)相似的内容:

【Azure K8S】演示修复因AKS密钥过期而导致创建服务不成功的问题(The provided client secret keys for app ****** are expired)

问题描述 在Azure Kubernetes 服务中,创建一个Internal Load Balancer服务,使用以下yaml内容: internallb.yaml apiVersion: v1 kind: Service metadata: name: ilb-myapp annotations

【Azure K8S | AKS】在中国区AKS上遇见ImagePullBackOff时的替代方案

Failed to pull image "k8s.gcr.io/cluster-proportional-autoscaler-amd64:1.1.2-r2": rpc error: code = Unknown desc = Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled wh

【Azure K8S | AKS】分享从AKS集群的Node中查看日志的方法(/var/log)

问题描述 使用Azure Kubernetes服务(AKS),可以通过kubectl连接 pod 中查看日志,但是如何来查看节点的系统日志呢?如是否有ubuntu系统升级的记录? 问题解答 是的,可以进入AKS的节点查看系统文件,如日志文件(/var/log) 或者由应用生产的其他日志。 具体的操作

【Azure K8S】AKS升级 Kubernetes version 失败问题的分析与解决

问题描述 创建Azure Kubernetes Service服务后,需要升级AKS集群的 kubernetes version。在AKS页面的 Cluster configuration 页面中,选择新的版本 1.25.5,确认升级。等待50分钟左右,却等到了升级失败的消息: Failed to

【Azure K8S】记录AKS VMSS实例日志收集方式

问题描述 如何从AKS的VMSS集群中收集实例日志? 参考步骤 第一步:登陆VMSS实例 参考官网步骤:使用 SSH 连接到 Azure Kubernetes 服务 (AKS) 群集节点以进行维护或故障排除: https://docs.azure.cn/zh-cn/aks/ssh#configure

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例

问题描述 在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例 问题解答 在Azure Kubernetes Service(AKS)的官方网站中,关于存储的选项介绍中,并没有具体的yaml实例来创建PV, PVC。特别是使用自定

【Azure K8S | AKS】在不丢失文件/不影响POD运行的情况下增加PVC的大小

问题描述 在前两篇文章中,创建了Disk + PV + PVC + POD 方案后,并且进入POD中增加文件。 【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例 【Azure K8S|AKS】

【Azure K8S | AKS】在AKS中创建 StatefulSet 示例

问题描述 【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例 【Azure K8S|AKS】进入AKS的POD中查看文件,例如PVC Volume Mounts使用情况 【Azure K8S |

【Azure APIM】APIM self-host 部署在K8S中,如何更换证书呢?

问题描述 APIM self-host(自建网关)部署在K8S中,如何在本地上传及更换证书呢? 问题解答 如果使用Self-host网关,则不支持使用上传到 APIM的 CA 根证书验证服务器和客户端证书。 若要建立信任,请配置特定的客户端证书,使其被网关作为一个自定义的证书颁发机构所信任,使用网关

【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Linux/Linux Container)

在前一篇文章中,我们是把.NET 8应用读取SSL证书(X509)示例部署在App Service Windows环境中,那么如果部署在Linux环境,以及Linux Container中呢? 根据前文中的第一种方法,直接在把证书文件包含在源文件中,通过相对路径读取证书文件的方式,经测试,可以正常工