【问题标题】:How does Lens (Kubernetes IDE) get direct shell access to Kubernetes nodes without ssh keys?Lens (Kubernetes IDE) 如何在没有 ssh 密钥的情况下获得对 Kubernetes 节点的直接 shell 访问?
【发布时间】:2021-06-15 17:08:59
【问题描述】:

我找不到等效的 k8s cli 命令来执行此类操作,也找不到任何存储为 k8s 机密的 ssh 密钥。它似乎也以与云无关的方式执行此操作。

是否只是使用具有特殊权限的k8s pod之类的?

编辑:哎呀,它是开源的。我会调查并相应地更新这个问题

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    发布此社区 wiki 答案以更清楚地了解在解决此问题的 github 问题上发表的评论:

    Lens 将创建nsenter pod 到所选节点

    protected async createNodeShellPod(podId: string, nodeName: string) { 
      const kc = this.getKubeConfig(); 
      const k8sApi = kc.makeApiClient(k8s.CoreV1Api); 
      const pod = { 
        metadata: { 
          name: podId, 
          namespace: "kube-system" 
        }, 
        spec: { 
          restartPolicy: "Never", 
          terminationGracePeriodSeconds: 0, 
          hostPID: true, 
          hostIPC: true, 
          hostNetwork: true, 
          tolerations: [{ 
            operator: "Exists" 
          }], 
          containers: [{ 
            name: "shell", 
            image: "docker.io/alpine:3.9", 
            securityContext: { 
              privileged: true, 
            }, 
            command: ["nsenter"], 
            args: ["-t", "1", "-m", "-u", "-i", "-n", "sleep", "14000"] 
          }], 
          nodeSelector: { 
            "kubernetes.io/hostname": nodeName 
          } 
        } 
      } as k8s.V1Pod; 
    

    并在镜头终端中执行到该容器中。

    -- Github.com: Lensapp: Issues: How Lens accessing nodes in AKS/EKS without user and SSH key under ROOT?


    我已经检查过了,可以看到下面的Podnsenter 是在kube-system 中创建的(检查GKE):

    • $ kubectl get pods -n kube-system(输出已编辑)
    kube-system   node-shell-09f6baaf-dc4a-4faa-969e-8016490eb8e0             1/1     Running   0          10m
    

    其他资源:

    【讨论】:

      猜你喜欢
      • 2021-05-22
      • 2022-01-27
      • 2022-11-22
      • 2016-04-16
      • 2022-01-02
      • 2022-08-24
      • 2018-05-28
      • 2011-07-13
      • 2020-12-25
      相关资源
      最近更新 更多