How to update/reset kubernetes cluster config

ascii-c 31 Reputation points

I have deleted the first AKS setup I created as well as the resource group in Azure.
Then created a new one, Hyperledger-Fabric-on-Azure-Kubernetes-Service, which set to region US West.
The first one used region SouthAustralia.

After new AKS setup is done, I checked the pods and the context.

az_dev@Azure:~$ kubectl get current-context
Unable to connect to the server: dial tcp: lookup on no such host

Checking the the kube config, it still displays the old config.

az_dev@Azure:~$ kubectl config view
    apiVersion: v1
    - cluster:
        certificate-authority-data: xxxxxxxxxxxxxxxxxxxxxxxxxxx==
      name: hlf02-HLF-AKS
    - cluster:
        certificate-authority-data: xxx==
      name: hlf01-HLF-AKS
    - context:
        cluster: hlf02-HLF-AKS
        user: clusterUser_dev-hlf02_hlf02-HLF-AKS
      name: hlf02-HLF-AKS
    - context:
        cluster: hlf01-HLF-AKS
        user: clusterUser_dev-hlf01_hlf01-HLF-AKS
      name: hlf01-HLF-AKS
    current-context: hlf01-HLF-AKS
    kind: Config
    preferences: {}
    - name: clusterUser_dev-hlf02_hlf02-HLF-AKS
        client-certificate-data: xxxxxxxxxxxxxxxxxxxxxxxx==
        client-key-data: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        token: xxxxxxxxxxxxxxxxxxxx
    - name: clusterUser_dev-hlf01_hlf01-HLF-AKS
        client-certificate-data: xxxxxxxxxxxxxxxxx==
        client-key-data: xxxxxxxxxxxxxxxxxxxx==
        token: xxxxxxxxxxxxxxxxxx

How do I update the kube config?
If I update it manually from $HOME/.kube/config, how do I get the new values from the new cluster (token, client cert)?

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,987 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,664 questions
0 comments No comments
{count} votes

Accepted answer
  1. vipullag-MSFT 25,866 Reputation points


    kubectl is using kubeconfig which is no longer valid.

    You can get updated kubeconfig file via "az aks get-credentials" command, Link for reference.

    You can also remove previously configured kubeconfig context and config from kubectl command line, check this link for more info.

    Hope this helps.


    Please 'Accept as answer' if it helped, so that it can help others in the community looking for help on similar topics.

1 additional answer

Sort by: Most helpful
  1. ascii-c 31 Reputation points

    @vipullag-MSFT This one detects the newly the westus cluster.

     az_dev@Azure:~$ az aks list --resource-group dev-hlf1 --subscription xxxx-xxx-xxxx-xx-xxxxxxxxxxx
     "aadProfile": null,
     "addonProfiles": {
     "httpApplicationRouting": {
     "config": {
     "HTTPApplicationRoutingZoneName": ""
     "enabled": true,
     "identity": null
     "omsagent": {
     "config": {
     "logAnalyticsWorkspaceResourceID": "/subscriptions/xxxx-xxxx-xxx-xxxx-xxxxx/resourceGroups/dev-hlf1/providers/microsoft.operationalinsights/workspaces/hlf12020-06-12T02-18-57"
     "enabled": true,
     "identity": null
     "agentPoolProfiles": [
     "availabilityZones": null,
     "count": 2,
     "enableAutoScaling": null,
     "enableNodePublicIp": null,
     "maxCount": null,
     "maxPods": 30,
     "minCount": null,
     "mode": "User",
     "name": "agentpool",
     "nodeLabels": null,
     "nodeTaints": null,
     "orchestratorVersion": "1.15.11",
     "osDiskSizeGb": 128,
     "osType": "Linux",
     "provisioningState": "Succeeded",
     "scaleSetEvictionPolicy": null,
     "scaleSetPriority": null,
     "spotMaxPrice": null,
     "tags": null,
     "type": "AvailabilitySet",
     "vmSize": "Standard_B2s"
     "apiServerAccessProfile": null,
     "autoScalerProfile": null,
     "diskEncryptionSetId": null,
     "dnsPrefix": "dev-hlf1-HLF-AKS-dns",
     "enablePodSecurityPolicy": null,
     "enableRbac": true,
     "fqdn": "",
     "id": "/subscriptions/xxxx-xxxx-xxxx-xxxx-xxxxxxx/resourcegroups/dev-hlf1/providers/Microsoft.ContainerService/managedClusters/dev-hlf1-HLF-AKS",
     "identity": null,
     "identityProfile": null,
     "kubernetesVersion": "1.15.11",
     "linuxProfile": null,
     "location": "westus",
     "maxAgentPools": 1,
     "name": "dev-hlf1-HLF-AKS",
     "networkProfile": {
     "dnsServiceIp": "",
     "dockerBridgeCidr": "",
     "loadBalancerProfile": null,
     "loadBalancerSku": "Basic",
     "networkMode": null,
     "networkPlugin": "azure",
     "networkPolicy": null,
     "outboundType": "loadBalancer",
     "podCidr": null,
     "serviceCidr": ""
     "nodeResourceGroup": "MC_dev-hlf1_dev-hlf1-HLF-AKS_westus",
     "privateFqdn": null,
     "provisioningState": "Succeeded",
     "resourceGroup": "dev-hlf1",
     "servicePrincipalProfile": {
     "clientId": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxx"
     "sku": {
     "name": "Basic",
     "tier": "Free"
     "type": "Microsoft.ContainerService/ManagedClusters",
     "windowsProfile": null