lensapp / lens

Lens - The way the world runs Kubernetes
https://k8slens.dev/
MIT License
22.29k stars 1.45k forks source link

Unable to exec into pods #3756

Open mjseid opened 2 years ago

mjseid commented 2 years ago

Describe the bug Pod Shell and attach to pod not working. They give the error:

$ kubectl exec -i -t -n mynamespace kafka-0 -c kafka "--" sh -c "clear; (bash || ash || sh)"
Unable to connect to the server: dial tcp 127.0.0.1:51271: socket: The requested service provider could not be loaded or initialized.

I am able to connect, edit and save pod configs, and view pod logs. But the exec functionality doesn't work.

To Reproduce Steps to reproduce the behavior:

  1. Connect to a cluster with Lens
  2. Navigate to a running pod
  3. Click the "PodShell" button
  4. See error displayed in the terminal

Expected behavior It is expected that a session is opened to the pod via the kubectl proxy

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Logs: When you run the application executable from command line you will see some logging output. Please paste them here:

Your logs go here...

Kubeconfig: Quite often the problems are caused by malformed kubeconfig which the application tries to load. Please share your kubeconfig, remember to remove any secret and sensitive information.

apiVersion: v1
kind: Config
clusters:
- name: arn:aws:eks:us-east-1:123456789:cluster/mycluster
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - --region
      - us-east-1
      - eks
      - get-token
      - --cluster-name
      - myclustername
      command: aws
contexts:
- context:
    cluster: arn:aws:eks:us-east-1:123456789:cluster/mycluster
    user: arn:aws:eks:us-east-1:123456789:cluster/mycluster
  name: arn:aws:eks:us-east-1:123456789:cluster/mycluster
preferences: {}
current-context: arn:aws:eks:us-east-1:123456789:cluster/mycluster

Additional context I can curl the kubectl proxy process by using a new terminal on my machine.

$ curl http://127.0.0.1:51271/api-kube/api/v1/namespaces
<!doctype html><html lang="en"><head><meta charset="UTF-8"><link href="/build/Lens.css" rel="stylesheet"></head><body><div id="app"></div><script src="/build/Lens.js"></script></body></html>

but the same curl from the terminal in lens fails:

$ curl http://127.0.0.1:51271/api-kube/api/v1/namespaces
curl: (7) Couldn't connect to server
Nokel81 commented 2 years ago

Do you see this same error if you try and exec into a pod using lens to a different cluster?

Are you able to run the kubectl exec ... command from above in a shell yourself? Does it work?

mjseid commented 2 years ago

Yes, I get the error any pod in any cluster.

If I take the command from the lens terminal, copy and past into a gitbash terminal it works fine. Any other troubleshooting steps I can do?

vasyakrg commented 2 years ago

me too

i import my clusters to Rancher 2.6 my example config:

apiVersion: v1
kind: Config
clusters:
- name: "ams-do"
  cluster:
    server: "https://domain.ru/k8s/clusters/c-m-12345"

users:
- name: "ams-do"
  user:
    token: "kubeconfig-user-tokenj"

contexts:
- name: "ams-do"
  context:
    user: "ams-do"
    cluster: "ams-do"

current-context: "ams-do"

from command line (iTerm + zsh) - all is OK.

but from Lens: exec kubectl exec -i -t -n kafka kafka-kafka-0 -c kafka -- sh -c "clear; (bash || ash || sh)"

error: error: unable to upgrade connection: error dialing backend: read tcp 192.168.9.64:49347-><my-lb-from-rancher>:443: read: operation timed out

no proxies in my configs

if i set config from cluster without Rancer - all ok. whats wrong ?

alessioga commented 1 year ago

Getting a similar issue on Linux