可以使用以下命令获取集群凭据,并从结果中提取大写字母的集群名称。
# 获取集群凭据
az aks get-credentials --resource-group --name
# 从结果中提取大写字母的集群名称
cluster_name=$(kubectl config view -o jsonpath='{.contexts[?(@.name == "")].context.cluster}')
其中,
为资源组名称,
为集群名称。最后一行代码使用 kubectl config view
命令从 Kubernetes 配置文件中提取大写字母的集群名称。