我需要连接到Azure Kubernetes以使用我自己的CLI工具

ergxz8rk  于 5个月前  发布在  Kubernetes
关注(0)|答案(1)|浏览(63)

以下场景
我用python写了自己的CLI工具,想建立一个到AKS的连接。因为我发现只有REST API才有可能(如果有其他方法,请告诉我)有人有这方面的经验吗?我该怎么做?
有一些命令,比如删除运行中的pod。非常基本的东西到这里。
在未来,通过令牌进行身份验证以涵盖安全方面也很重要。
我会很高兴的解决方案和答案。
我对AKS只有基本的经验,这就是为什么我问这个问题。而且大多数用户只是使用kubectl或其他工具,所以在谷歌上搜索它之后没有太多的方向

xdyibdwo

xdyibdwo1#

要使用Python CLI连接到AKS,可以使用Azure管理API(如Azure SDK for Python(Azure管理容器))来使用AKS API
确保已安装Azure SDK for Python,并且已配置最新版本的Azure CLI。

pip install azure-mgmt-containerservice

字符串


的数据

from azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClient
from azure.mgmt.containerservice.models import ManagedCluster

#Authenticate
credential = DefaultAzureCredential()

#Specify your Azure subscription ID and resource group
subscription_id = "your_subscription_id"
resource_group = "your_resource_group"
cluster_name = "your_cluster_name"

#Create a ContainerServiceClient
client = ContainerServiceClient(credential, subscription_id)

#Get information about the AKS cluster
cluster = client.managed_clusters.get(resource_group, cluster_name)

print(f"AKS Cluster Name: {cluster.name}")
print(f"AKS Cluster Location: {cluster.location}")
print(f"AKS Cluster Kubernetes Version: {cluster.kubernetes_version}")


输出:

另一种方法是使用kubeconfig文件或bearer token,如matt_j的here所述

相关问题