Unable to connect aks cluster using github actions

Uday Kiran Reddy (ureddy) 56 Reputation points
2021-11-02T12:17:09.527+00:00

I am trying to connect to cluster and create a namespace using github actions.
For that, I tried these steps.

In the link shared above, I first retrieved the azure service principal for connecting aks.

az ad sp create-for-rbac --name "myApp" --role contributor --scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP> --sdk-auth

And then, proceeded with the steps.
But, during namespace creation, I am getting error as below.

W1102 12:06:42.227952 3700 helpers.go:555] --dry-run is deprecated and can be replaced with --dry-run=client.
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Error: Process completed with exit code 1.

Below is the github job failing.

  • name: Set the target Azure Kubernetes Service (AKS) cluster.
    uses: azure/aks-set-context@v1
    with:
    creds: '${{ secrets.AZURE_CREDENTIALS }}'
    cluster-name: ${{ env.CLUSTER_NAME }}
    resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }}
    • name: Deploy to Cluster
      uses: azure/k8s-deploy@v1
      with:
      manifests: |
      manifests/deployment.yml
      manifests/service.yml
      images: |
      ${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.APP_NAME }}:${{ github.sha }}
      imagepullsecrets: |
      ${{ env.SECRET }}
      namespace: ${{ env.NAMESPACE }}
Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,118 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. shiva patpi 9,171 Reputation points Microsoft Employee
    2021-11-03T03:21:50.487+00:00

    @Uday Kiran Reddy (ureddy) ,
    Normally that error means some issue with the kube config file. It seems kubectl attempting to connect to localhost for the control plane server instead of actual AKS cluster.
    Try to run az aks get-credentials -g <resourcegroupname> -n <aksclustername> --overwrite
    Validate the output of : kubectl config current-context (Make sure it is set to right AKS cluster)

    Regards,
    Shiva.