Home > Enterprise >  Errors when trying to connect to kubernetes
Errors when trying to connect to kubernetes

Time:09-27

I've been trying to connect to k8s cluster which is running in azure from my Mac laptop, but unfortunately I can't retrieve any information.

user@MyMac ~ % k get nodes                                   
error: unknown flag: --environment
error: unknown flag: --environment
error: unknown flag: --environment
Unable to connect to the server: getting credentials: exec: executable kubelogin failed with exit code 1

when I extend the log I get this:

user@MyMac ~ % kubectl get deployments --all-namespaces=true -v 8
I0924 10:32:14.451255   28517 loader.go:372] Config loaded from file:  /Users/user/.kube/config
I0924 10:32:14.461468   28517 round_trippers.go:432] GET https://dev-cluster.privatelink.westeurope.azmk8s.io:443/api?timeout=32s
I0924 10:32:14.461484   28517 round_trippers.go:438] Request Headers:
I0924 10:32:14.461490   28517 round_trippers.go:442]     Accept: application/json, */*
I0924 10:32:14.461495   28517 round_trippers.go:442]     User-Agent: kubectl/v1.22.5 (darwin/amd64) kubernetes/5c99e2a
error: unknown flag: --environment
I0924 10:32:14.555302   28517 round_trippers.go:457] Response Status:  in 93 milliseconds
I0924 10:32:14.555318   28517 round_trippers.go:460] Response Headers:
I0924 10:32:14.555828   28517 cached_discovery.go:121] skipped caching discovery info due to Get "https://dev-cluster.privatelink.westeurope.azmk8s.io:443/api?timeout=32s": getting credentials: exec: 
I0924 10:32:14.569821   28517 shortcut.go:89] Error loading discovery information: Get "https://dev-cluster.privatelink.westeurope.azmk8s.io:443/api?timeout=32s": getting credentials: exec: executable kubelogin failed with exit code 1
I0924 10:32:14.570037   28517 round_trippers.go:432] GET https://dev-cluster.privatelink.westeurope.azmk8s.io:443/api?timeout=32s
I0924 10:32:14.570050   28517 round_trippers.go:438] Request Headers:
I0924 10:32:14.570068   28517 round_trippers.go:442]     Accept: application/json, */*
I0924 10:32:14.570088   28517 round_trippers.go:442]     User-Agent: kubectl/v1.22.5 (darwin/amd64) kubernetes/5c99e2a

I0924 10:32:14.618944   28517 round_trippers.go:457] Response Status:  in 17 milliseconds
I0924 10:32:14.618976   28517 round_trippers.go:460] Response Headers:
I0924 10:32:14.619147   28517 cached_discovery.go:121] skipped caching discovery info due to Get "https://dev-cluster.privatelink.westeurope.azmk8s.io:443/api?timeout=32s": getting credentials: exec: executable kubelogin failed with exit code 1
I0924 10:32:14.619790   28517 helpers.go:235] Connection error: Get https://dev-cluster.privatelink.westeurope.azmk8s.io:443/api?timeout=32s: getting credentials: exec: executable kubelogin failed with exit code 1
F0924 10:32:14.620768   28517 helpers.go:116] Unable to connect to the server: getting credentials: exec: executable kubelogin failed with exit code 1
goroutine 1 [running]:
k8s.io/kubernetes/vendor/k8s.io/klog/v2.stacks(0xc0000cc001, 0xc000258000, 0x97, 0x23d)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/klog/v2/klog.go:1026  0xb9
k8s.io/kubernetes/vendor/k8s.io/klog/v2.(*loggingT).output(0x3cd80e0, 0xc000000003, 0x0, 0x0, 0xc0004d8150, 0x2, 0x33f6d63, 0xa, 0x74, 0x100e100)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/klog/v2/klog.go:975  0x1e5
k8s.io/kubernetes/vendor/k8s.io/klog/v2.(*loggingT).printDepth(0x3cd80e0, 0xc000000003, 0x0, 0x0, 0x0, 0x0, 0x2, 0xc0004e0db0, 0x1, 0x1)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/klog/v2/klog.go:735  0x185
k8s.io/kubernetes/vendor/k8s.io/klog/v2.FatalDepth(...)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/klog/v2/klog.go:1500
k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/util.fatal(0xc00081c3f0, 0x68, 0x1)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/util/helpers.go:94  0x288
k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/util.checkErr(0x2e6b0e0, 0xc0004e7410, 0x2cebdc8)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/util/helpers.go:189  0x935
k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/util.CheckErr(...)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/util/helpers.go:116
k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/get.NewCmdGet.func2(0xc0001ef680, 0xc000820cc0, 0x1, 0x4)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/cmd/get/get.go:180  0x159
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).execute(0xc0001ef680, 0xc000820c80, 0x4, 0x4, 0xc0001ef680, 0xc000820c80)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:856  0x2c2
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000401180, 0xc0000ce180, 0xc0000ce120, 0x6)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:960  0x375
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).Execute(...)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:897
main.main()
    _output/dockerized/go/src/k8s.io/kubernetes/cmd/kubectl/kubectl.go:49  0x21d

goroutine 18 [chan receive]:
k8s.io/kubernetes/vendor/k8s.io/klog/v2.(*loggingT).flushDaemon(0x3cd80e0)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/klog/v2/klog.go:1169  0x8b
created by k8s.io/kubernetes/vendor/k8s.io/klog/v2.init.0
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/klog/v2/klog.go:420  0xdf

goroutine 23 [select]:
k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.BackoffUntil(0x2cebcd0, 0x2e695e0, 0xc0004e6000, 0x1, 0xc00009eb40)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:167  0x118
k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil(0x2cebcd0, 0x12a05f200, 0x0, 0x1, 0xc00009eb40)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:133  0x98
k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.Until(0x2cebcd0, 0x12a05f200, 0xc00009eb40)
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:90  0x4d
created by k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/util/logs.InitLogs
    /workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/k8s.io/kubectl/pkg/util/logs/logs.go:51  0x96

I updated the az cli, but nothing changed. I removed too the .kube/config file, and it didn't work too. I don't know what went wrong after the update of the MacOs.

CodePudding user response:

This happens because the ./kube config file was rewritten in the upgrade process, so you would need to add the credentials, run this command to refresh them:

az aks get-credentials --resource-group group --name cluster-name --admin --overwrite-existing

Details of the Kubernetes Service Connection:

  1. Authentication method: Azure Subscription
  2. Azure Subscription:
  3. Cluster:
  4. Namespace:
  5. Use cluster admin credentials
  • Related