when I try to check the version of Kubectl with kubectl version that is installed in my local desktop. i got the following error
"Unable to connect to the server: dial tcp: lookup myaksclust-myresourcegroup-3f2c36-40a876eb.hcp.eastus.azmk8s.io: no such host"
I check the kubectl configuration file with Kubectl config view
it shows with information below
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://aks-cluste-aks-rg-3f2c36-a86fa58c.hcp.eastus.azmk8s.io:443
name: aks-cluster
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://kubernetes.docker.internal:6443
name: docker-desktop
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://kuar-clust-kuar-3f2c36-3176b3bf.hcp.eastus.azmk8s.io:443
name: kuar-cluster
- cluster:
certificate-authority: C:\Users\admin\.minikube\ca.crt
server: https://192.168.2.14:8443
name: minikube
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://myaksclust-myresourcegroup-3f2c36-40a876eb.hcp.eastus.azmk8s.io:443
name: myAKSCluster
contexts:
- context:
cluster: aks-cluster
user: clusterUser_aks-rg_aks-cluster
name: aks-cluster
- context:
cluster: docker-desktop
user: docker-desktop
name: docker-desktop
- context:
cluster: kuar-cluster
user: clusterUser_kuar_kuar-cluster
name: kuar-cluster
- context:
cluster: minikube
user: minikube
name: minikube
- context:
cluster: myAKSCluster
user: clusterUser_myResourceGroup_myAKSCluster
name: myAKSCluster
current-context: myAKSCluster
kind: Config
preferences: {}
users:
- name: clusterUser_aks-rg_aks-cluster
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
token: e4d785d3065d5697f03ac404ac27460f68b973b7185ea4697679077e39ff106437d3a7fe9c79f3be5cc84bbab6728e2d71bc010d0a6c6628bf05162958c122bb
- name: clusterUser_kuar_kuar-cluster
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
token: afc713faf0d9c13f494711c3ab569d52c48c4ac1bef72f53329ab832247c0180f87a167d59c1a784ea0951bd11f043e8eb8aa6089caec2d9d71f61ea58d29b48
- name: clusterUser_myResourceGroup_myAKSCluster
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
token: 2906f9edf219806a855010df4aa104f25eceea94ce748cf1b7813f3af93c531a60b853654b6bc0b24c448491ab3a5896ad36e0fa00d898507c44db7c69f8b283
- name: docker-desktop
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
- name: minikube
user:
client-certificate: C:\Users\admin\.minikube\profiles\minikube\client.crt
client-key: C:\Users\admin\.minikube\profiles\minikube\client.key
we can see that the current-context is myAKSCluster, which is Azure Kubernetes Service. the error is sterm from that either authoriation token had been expired or the service instance had been removed from azure
Since we already know the root cause of the issue, we can change the kubectl context to the new AKS or the local docker-desktop.
we can follow the steps below
#to get all the context available in the kubectl configuration file
kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
aks-cluster aks-cluster clusterUser_aks-rg_aks-cluster
docker-desktop docker-desktop docker-desktop
kuar-cluster kuar-cluster clusterUser_kuar_kuar-cluster
minikube minikube minikube
* myAKSCluster myAKSCluster clusterUser_myResourceGroup_myAKSCluster
#update the current context with local docker-desktop
kubectl config use-context docker-desktop