others-how to solve Unable to connect to the server: tls: first record does not look like a TLS handshake
Problem
When we kubectl as follows, sometimes, we get this error or exception:
root@launch-advisor:~# kubectl get nodes
Unable to connect to the server: tls: first record does not look like a TLS handshake
Environment
-
Docker: Server Version: 19.03.13
-
Kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-13T18:06:54Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"darwin/amd64"} Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.6", GitCommit:"dff82dc0de47299ab66c83c626e08b245ab19037", GitTreeState:"clean", BuildDate:"2020-07-15T16:51:04Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Reason
This error :
Unable to connect to the server: tls: first record does not look like a TLS handshake
is caused by the network proxy settings of your client.
Solution
Because I am using spechtLite as system proxy as follows:
A proxy’s definition from wikipedia.org is as follows :
a proxy server is a server application or appliance that acts as an intermediary for requests from clients seeking resources from servers that provide those resources.[1] A proxy server thus functions on behalf of the client when requesting service, potentially masking the true origin of the request to the resource server.
If the proxy fails, then the connection would fail, So I choose to stop the proxy server as follows:
Restart the terminal , and then re-execute the command as follows:
➜ ~ k get nodes
NAME STATUS ROLES AGE VERSION
bswen-k8s-app2 Ready worker 8d v1.18.6
bswen-k8s-app3 Ready worker 8d v1.18.6
bswen-k8s-app4 Ready worker 8d v1.18.6
bswen-k8s-app5 Ready worker 8d v1.18.6
bswen-k8s-app1 Ready worker 8d v1.18.6
➜ ~
Everything works!