如何使用containerd运行时ssh到同类集群节点?

dee*_*pak 6 kubernetes containerd kind

我已经使用 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
Run Code Online (Sandbox Code Playgroud)

我如何 ssh 进入节点?

种类版本:0.11.1 或更高版本

运行时:containerd(不是docker)

Mik*_* S. 10

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

\n
\n

kind是使用 Docker 容器 \xe2\x80\x9cnodes\xe2\x80\x9d 运行本地 Kubernetes 集群的工具。

\n
\n

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

\n

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

\n

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

\n
NAME                 STATUS   ROLES                  AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE       KERNEL-VERSION    CONTAINER-RUNTIME\nkind-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\nkind-worker          Ready    <none>                 4m38s   v1.21.1   172.18.0.4    <none>        Ubuntu 21.04   5.11.0-1017-gcp   containerd://1.5.2\nkind-worker2         Ready    <none>                 4m35s   v1.21.1   172.18.0.3    <none>        Ubuntu 21.04   5.11.0-1017-gcp   containerd://1.5.2\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

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

\n
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS         PORTS                       NAMES\n7ee204ad5fd1   kindest/node:v1.21.1   "/usr/local/bin/entr\xe2\x80\xa6"   10 minutes ago   Up 8 minutes                               kind-worker\n434f54087e7c   kindest/node:v1.21.1   "/usr/local/bin/entr\xe2\x80\xa6"   10 minutes ago   Up 8 minutes   127.0.0.1:35085->6443/tcp   kind-control-plane\n2cb2e9465d18   kindest/node:v1.21.1   "/usr/local/bin/entr\xe2\x80\xa6"   10 minutes ago   Up 8 minutes                               kind-worker2\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

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

\n
# ls\nbin  boot  dev  etc  home  kind  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var\n# ip a\n1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\n...\n11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default \n    inet 172.18.0.4/16 brd 172.18.255.255 scope global eth0\n    ...\n# \n
Run Code Online (Sandbox Code Playgroud)\n

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

\n