Search code examples
amazon-web-serviceskubernetesamazon-ec2kubectlamazon-eks

kubectl doesn't load the new endpoint to connect


When i run kubectl get svc i have the error Unable to connect to the server: dial tcp: lookup DB3E0792B37BE7363D42AF594F4C72AB.gr7.eu-centrale-1.xx.

I update my ~/.kube/config to add the new endpoint https://6AF7819922F51E229C9B408FE5DXXXXXXX.gr7.eu-central-1.

However It seems kubectl doesn't load the new endpoint. Because if i run again kubectl get svc he try to connect to same previous endpoint


Solution

  • If you have multiple cluster contexts. Use kubectl to edit this and target the context you wish to edit.

    $ kubectl config view
    apiVersion: v1
    clusters:
    - cluster:
      certificate-authority-data: DATA+OMITTED
      server: https://10.0.0.10:6443
    name: default
    .....
    

    To update the endpoint to from 10.0.0.10 to 192.168.0.1:

    $ kubectl config set-cluster default --server=https://192.168.0.1
    Cluster "default" set.
    

    Validate the update is correct:

    $ kubectl config view
    apiVersion: v1
    clusters:
    - cluster:
      certificate-authority-data: DATA+OMITTED
      server: https://192.168.0.1
    name: default
    ....
    

    Also ensure you have switched to the correct context by (in this case "default") context:

    $ kubectl config use-context default
    Switched to context "default".