首页 > 解决方案 > 如何使用 containerd 运行时 ssh 进入种类集群节点?

问题描述

我创建了一个带有 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)

标签: kubernetescontainerdkind

解决方案


Kind Kuberenetes 使用 Docker创建容器,该容器将成为 Kubernetes 节点

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…&quot;   10 minutes ago   Up 8 minutes                               kind-worker
434f54087e7c   kindest/node:v1.21.1   "/usr/local/bin/entr…&quot;   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…&quot;   10 minutes ago   Up 8 minutes                               kind-worker2

看一下NAMES专栏——这里是 Kubernetes 中使用的节点名称。

现在我们将使用标准docker exec命令连接到正在运行的容器并连接到它的 shell - 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 地址与命令中的 IP 地址172.18.0.4匹配kubectl get nodes


推荐阅读