Search code examples
azure-devopsazure-pipelinesazure-aks

Azure Devops Kubernetes@1 login


I want to login onto an AKS cluster and run kubectl commands.

According to the docs I can login

steps:    
- task: Kubernetes@1
  inputs:
    connectionType: 'Kubernetes Service Connection'
    kubernetesServiceEndpoint: 'aks-xxx'
    command: 'login'

- bash: |
    kubectl get pod

The login is succesfull but the bash script is not:

Unable to connect to the server: dial tcp: lookup api.mycluster.com on 127.0.0.53:53: no such host

In bash I can also see that the config file on $KUBECONFIG is almost empty


Solution

  • It appears that you are using a private cluster. See Create a private Azure Kubernetes Service cluster for details.

    Kubectl is a kubernetes control client. It is an external connectivity provider to connect with our kubernetes cluster. We can't connect with the private cluster externally. See Options for connecting to the private cluster for details.

    The API server endpoint has no public IP address. To manage the API server, you'll need to use a VM that has access to the AKS cluster's Azure Virtual Network (VNet).

    There are several options for establishing network connectivity to the private cluster.

    • Create a VM in the same Azure Virtual Network (VNet) as the AKS cluster.
    • Use a VM in a separate network and set up Virtual network peering. See the section below for more information on this option.
    • Use an Express Route or VPN connection.
    • Use the AKS command invoke feature.
    • Use a private endpoint connection.

    So, you can try to setup and use a self hosted agent on the VM within the same Azure Virtual Network (VNet) as the AKS cluster.

    Alternately, create a new public cluster and then try it again. Test the scenario and it works as expected in my side: enter image description here