【问题标题】:How to ssh into kind cluster nodes with containerd runtime?如何使用 containerd 运行时 ssh 进入种类集群节点?
【发布时间】:2021-11-05 12:33:10
【问题描述】:

我创建了一个带有 containerd 运行时的 Kind 集群。 这是我的节点:

root@dev-001:~# k get nodes -o wide
NAME                          STATUS   ROLES                  AGE    VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE       KERNEL-VERSION     CONTAINER-RUNTIME
local-cluster-control-plane   Ready    control-plane,master   7d8h   v1.20.2   172.18.0.2    <none>        Ubuntu 20.10   5.4.0-81-generic   containerd://1.4.0-106-gce4439a8
local-cluster-worker          Ready    <none>                 7d8h   v1.20.2   172.18.0.5    <none>        Ubuntu 20.10   5.4.0-81-generic   containerd://1.4.0-106-gce4439a8
local-cluster-worker2         Ready    <none>                 7d8h   v1.20.2   172.18.0.3    <none>        Ubuntu 20.10   5.4.0-81-generic   containerd://1.4.0-106-gce4439a8
local-cluster-worker3         Ready    <none>                 7d8h   v1.20.2   172.18.0.4    <none>        Ubuntu 20.10   5.4.0-81-generic   containerd://1.4.0-106-gce4439a8

如何通过 ssh 进入节点?

种类版本:0.11.1 或更高版本

运行时:containerd(不是 docker)

【问题讨论】:

  • @WytrzymałyWiktor 不
  • @deepak 以下这些答案有足够的信息来解决您的问题。否则,请更新您的问题,详细说明问题出在哪里、卡在哪里、错误,以及任何有助于理解什么不起作用的内容。

标签: kubernetes containerd kind


【解决方案1】:

一个简单的谷歌搜索将揭示答案:

https://cloud.google.com/anthos/clusters/docs/on-prem/1.3/how-to/ssh-cluster-node


使用 SSH 连接用户集群节点

  • 获取用户集群的 SSH 密钥:
kubectl --kubeconfig [ADMIN_CLUSTER_KUBECONFIG] get secrets \
        -n [USER_CLUSTER_NAME] ssh-keys \
        -o jsonpath='{.data.ssh\.key}' | base64 -d > \
        ~/.ssh/[USER_CLUSTER_NAME].key \
        && chmod 600 ~/.ssh/[USER_CLUSTER_NAME].key

地点:

[ADMIN_CLUSTER_KUBECONFIG] 是管理集群的 kubeconfig 文件的路径。

[USER_CLUSTER_NAME] 是您的用户集群的名称。


上述命令执行以下步骤:

  • 从管理员集群中,获取 [USER_CLUSTER_NAME] 命名空间中名为 ssh-keys 的 Secret 的 ssh.key 字段。
  • Base64 对密钥进行解码。
  • 将解码后的密钥存储在文件 ~/.ssh/[USER_CLUSTER_NAME].key 中。
  • 为密钥文件设置适当的访问权限。

使用密钥 SSH 进入用户集群节点:

ssh -i ~/.ssh/[USER_CLUSTER_NAME].key user@[NODE_IP]

地点:

  • [NODE_IP] 是您之前收集的用户集群中节点的内部 IP 地址。

【讨论】:

  • 不使用 gke/anthos 集群,我们拥有带有 containerd 运行时的类型 (kind.sigs.k8s.io) 本地集群。 ``` 名称状态角色年龄版本内部IP 外部IP 操作系统映像内核版本容器运行时间本地集群控制平面就绪控制平面,master 7d8h v1.20.2 172.18.0.2 Ubuntu 20.10 5.4。 0-81-generic containerd://1.4.0-106-gce4439a8 ```
【解决方案2】:

Kuberenetes 使用 Docker 来create container(s) which will be Kubernetes node(s)

kind 是一个使用 Docker 容器“节点”运行本地 Kubernetes 集群的工具。

所以基本上这些层是:您的主机 -> 托管在您主机的 docker 上的容器,它们充当 Kubernetes 节点 -> 在节点上有用于运行 pod 的容器运行时

为了通过 SSH 连接到节点,您需要执行到 docker 容器中。让我们去做吧。

首先,我们将通过运行kubectl get nodes -o wide获取节点列表:

NAME                 STATUS   ROLES                  AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE       KERNEL-VERSION    CONTAINER-RUNTIME
kind-control-plane   Ready    control-plane,master   5m5s    v1.21.1   172.18.0.2    <none>        Ubuntu 21.04   5.11.0-1017-gcp   containerd://1.5.2
kind-worker          Ready    <none>                 4m38s   v1.21.1   172.18.0.4    <none>        Ubuntu 21.04   5.11.0-1017-gcp   containerd://1.5.2
kind-worker2         Ready    <none>                 4m35s   v1.21.1   172.18.0.3    <none>        Ubuntu 21.04   5.11.0-1017-gcp   containerd://1.5.2

假设我们想通过 SSH 连接到 kind-worker 节点。

现在,我们将获取 docker 容器列表 (docker ps -a) 并检查是否所有节点都在这里:

CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS         PORTS                       NAMES
7ee204ad5fd1   kindest/node:v1.21.1   "/usr/local/bin/entr…"   10 minutes ago   Up 8 minutes                               kind-worker
434f54087e7c   kindest/node:v1.21.1   "/usr/local/bin/entr…"   10 minutes ago   Up 8 minutes   127.0.0.1:35085->6443/tcp   kind-control-plane
2cb2e9465d18   kindest/node:v1.21.1   "/usr/local/bin/entr…"   10 minutes ago   Up 8 minutes                               kind-worker2

查看NAMES 列 - 这是 Kubernetes 中使用的节点名称。

现在我们将使用标准 docker exec command 连接到正在运行的容器并连接到它的外壳 - docker exec -it kind-worker sh,然后我们将在容器上运行 ip a 以检查 IP 地址是否与来自 kubectl get nodes 的地址匹配命令:

# ls
bin  boot  dev  etc  home  kind  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
...
11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    inet 172.18.0.4/16 brd 172.18.255.255 scope global eth0
    ...
# 

可以看到,我们成功连接到 Kind Kubernetes 使用的节点 - IP 地址172.18.0.4 与来自kubectl get nodes 命令的 IP 地址匹配。

【讨论】:

  • 尝试使用最新版本的种类和运行时,而不是 docker
  • @deepak - "While kind uses docker or podman on your host, it uses CRI / containerd "inside" the nodes" - 我使用 containerd 作为节点上的运行时(在我的回答中检查 kubectl get nodes -o wide 的输出)在主机上我使用 docker 因为 kind 只支持docker 或 podman - 默认情况下它是 docker,所以我假设你可能也在使用它。
  • @deepak - 检查我的other answer 以获得更好的说明和了解 Kubernetes 的工作原理。
猜你喜欢
  • 2019-08-10
  • 2016-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-11
  • 2017-01-08
  • 2021-03-12
  • 1970-01-01
相关资源
最近更新 更多