如何使用 nsenter 实用程序从 POD 连接和管理 Kubernetes 集群
How do I connect and manage Kubernetes cluster from POD using nsenter utility
我正在使用多节点 Kubernetes 集群。我正在使用以下 YAML 来连接和管理主机。
apiVersion: v1
kind: Pod
metadata:
name: my-nsenter-test
spec:
hostPID: true
hostNetwork: true
hostIPC: true
containers:
- name: my-nsenter-test
image: ubuntu:18.04
command: ["tail"]
args: ["-f", "/dev/null"]
securityContext:
privileged: true
但我想使用单个 POD 连接和管理多节点集群(集群中的任何其他节点)。
简短回答:您可以使用 nsenter 实用程序从 pod 连接到唯一的一个节点 - pod 所在的节点,但最好不要这样做,因为部署pods 具有广泛的权限是违反最佳安全实践的。
您无法连接到其他节点,因为 pod 仅托管在一个节点上。设置 host...
字段意味着它们只是 sharing resources with the host - one host node 并且根本不可能使用 nsenter 实用程序实现它。
此图很好地表示了与 pods 和节点相关的 Kuberentes 架构:
为了连接到主机节点,只需 运行 以下命令:
kubectl exec -it my-nsenter-test -- nsenter --target 1 --mount --uts --ipc --net /bin/bash
避免使用特权策略并与主机一起托管公共资源
通常,这种管理主机的方法有悖于最佳安全实践。
强烈不建议授予 pod 广泛的权限,这会导致许多安全问题,usually it's granting broader permissions that intended:
The way PSPs are applied to Pods has proven confusing to nearly everyone that has attempted to use them. It is easy to accidentally grant broader permissions than intended, and difficult to inspect which PSP(s) apply in a given situation.
另请查看这篇文章 - Securing a Cluster。
我正在使用多节点 Kubernetes 集群。我正在使用以下 YAML 来连接和管理主机。
apiVersion: v1
kind: Pod
metadata:
name: my-nsenter-test
spec:
hostPID: true
hostNetwork: true
hostIPC: true
containers:
- name: my-nsenter-test
image: ubuntu:18.04
command: ["tail"]
args: ["-f", "/dev/null"]
securityContext:
privileged: true
但我想使用单个 POD 连接和管理多节点集群(集群中的任何其他节点)。
简短回答:您可以使用 nsenter 实用程序从 pod 连接到唯一的一个节点 - pod 所在的节点,但最好不要这样做,因为部署pods 具有广泛的权限是违反最佳安全实践的。
您无法连接到其他节点,因为 pod 仅托管在一个节点上。设置 host...
字段意味着它们只是 sharing resources with the host - one host node 并且根本不可能使用 nsenter 实用程序实现它。
此图很好地表示了与 pods 和节点相关的 Kuberentes 架构:
为了连接到主机节点,只需 运行 以下命令:
kubectl exec -it my-nsenter-test -- nsenter --target 1 --mount --uts --ipc --net /bin/bash
避免使用特权策略并与主机一起托管公共资源
通常,这种管理主机的方法有悖于最佳安全实践。
强烈不建议授予 pod 广泛的权限,这会导致许多安全问题,usually it's granting broader permissions that intended:
The way PSPs are applied to Pods has proven confusing to nearly everyone that has attempted to use them. It is easy to accidentally grant broader permissions than intended, and difficult to inspect which PSP(s) apply in a given situation.
另请查看这篇文章 - Securing a Cluster。