<p>I create a k8s deployment script with python, and to get the configuration from <code>kubectl</code>, I use the python command:</p>

<pre><code>from kubernetes import client, config

config.load_kube_config()
</code></pre>

<p>to get the azure aks configuration I use the following <code>az</code> commands:</p>

<pre><code>az login
az aks get-credentials --resource-group [resource group name] --name [aks name]
</code></pre>

<p>is there any way to get azure aks credential only from python and without the need of the <code>az</code> commands? </p>

<p>thanks!</p>

Mendi Neymark
<p>Yes, this can be done with the Azure Python SDK.</p>
<pre class="lang-py prettyprint-override"><code>from azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClient

credential = DefaultAzureCredential(exclude_cli_credential=True)
subscription_id = os.environ[&quot;AZURE_SUBSCRIPTION_ID&quot;]
container_service_client = ContainerServiceClient(credential, subscription_id)

kubeconfig = container_service_client.managed_clusters.list_cluster_user_credentials(&quot;resourcegroup-name&quot;, &quot;cluster-name&quot;).kubeconfigs[0]
</code></pre>
