I'm currently trying to deploy two microservices to my AKS cluster using github actions.
(I've already tried deploying it to minikube, which worked flawlessly).
The process:
- Build docker images and push to dockerhub
- Login using
azure/[email protected] - Setup kubectl using
azure/[email protected] - Deploy the microservices simply using
kubectl apply -f ./service-1/k8s
Note: ./service-1/k8s/ includes service.yaml, ingress.yaml & deployment.yaml, which all work correctly when deployed to minikube using the exact same process (minus az-specific steps).
Now then, the problem arises up on using (any) kubectl command. The error in the console is the following:
E0118 [time] 1792 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0118 [time] 1792 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0118 [time] 1792 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
unable to recognize "service-1/k8s/deployment.yaml": Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
unable to recognize "service-1/k8s/ingress.yaml": Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
unable to recognize "service-1/k8s/service.yaml": Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
Sadly I have no idea what this error means.
Thanks for your help!
The errors you're encountering indicate that
kubectlis trying to communicate with a Kubernetes cluster API server atlocalhost:8080, which is the default when no context is set, and it's failing to connect. This suggests thatkubectlis not configured with the correct context to your AKS cluster.In your GitHub Actions workflow, after setting up
kubectlwithazure/[email protected], you need to ensure thatkubectlis configured to use the credentials for your AKS cluster. Typically, this is done by using theaz aks get-credentialscommand with Azure CLI, which automatically sets the correct context inkubectlto communicate with your AKS cluster.Here's what you need to do in your GitHub Actions workflow to correct this:
After logging in with
azure/[email protected], fetch the credentials for your AKS cluster using Azure CLI:Confirm that the
kubectlcontext has been set to your AKS cluster:Apply your Kubernetes manifests with
kubectl:Here, I have already added the $rg, $clustername and $creds seperately in variables. Now I don't know If you're using a service principal to authenticate with Azure, if so, then ensure that the service principal has the necessary permissions to fetch credentials for the AKS cluster and perform the required operations.
Verify that the Azure credentials stored in GitHub Secrets (
$creds) have the correct format and contain all required fields (clientId,clientSecret,subscriptionId,tenantId).and last but not least, verify that the Kubernetes API server is running by checking the status of the
kube-apiserverpod using theBy ensuring
kubectlis correctly pointed at your AKS cluster, it should resolve the connection issues and allow your deployments to proceed.Kindly refer to below documentation for ease as it has demonstrated step by step process with example-
Deploy to Azure Kubernetes Services using GitHub Actions
Official MS Doc to build, test and deploy container images to AKS using github action
Similar issue resolution