I create a k8s deployment script with python, and to get the configuration from kubectl
, I use the python command:
from kubernetes import client, configconfig.load_kube_config()
to get the azure aks configuration I use the following az
commands:
az login
az aks get-credentials --resource-group [resource group name] --name [aks name]
is there any way to get azure aks credential only from python and without the need of the az
commands?
thanks!
Yes, this can be done with the Azure Python SDK.
from azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClientcredential = DefaultAzureCredential(exclude_cli_credential=True)
subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]
container_service_client = ContainerServiceClient(credential, subscription_id)kubeconfig = container_service_client.managed_clusters.list_cluster_user_credentials("resourcegroup-name", "cluster-name").kubeconfigs[0]