'kubectl get pods' 命令在 Windows 上失败,适用于 WSL2
'kubectl get pods' command fails on Windows, works on WSL2
kubernetes 文档includes通过 pod 列出容器镜像的示例命令:
List Container images by Pod
The formatting can be controlled further by using the range operation to iterate over elements individually.
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |\
sort
当我在我的 Debian WSL2 实例中 运行 这个命令时,它正确地列出了我在所有命名空间中 运行ning 的每个 pod 的容器。
当我在 Windows 命令行中 运行 执行相同的命令时,出现错误:error: a resource cannot be retrieved by name across all namespaces
:
C:\workspace>kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' | sort
error: a resource cannot be retrieved by name across all namespaces
这是 kubectl 的一个错误,还是这个命令只有 *nix?是否有一个独立于 OS 的命令,用于通过 pod 跨所有命名空间获取容器镜像?
(我在 WSL2 上 运行ning Debian,Windows 10 Enterprise。Docker 使用 WSL2 集成的桌面,K8S 和 minikube。)
来自k8s官方doc:
On Windows, you must double quote any JSONPath template that contains spaces (not single quote as shown above for bash). This in turn means that you must use a single quote or escaped double quote around any literals in the template. For example: kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.startTime}{'\n'}{end}"
我想这会解决你的问题。
kubernetes 文档includes通过 pod 列出容器镜像的示例命令:
List Container images by Pod
The formatting can be controlled further by using the range operation to iterate over elements individually.
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |\ sort
当我在我的 Debian WSL2 实例中 运行 这个命令时,它正确地列出了我在所有命名空间中 运行ning 的每个 pod 的容器。
当我在 Windows 命令行中 运行 执行相同的命令时,出现错误:error: a resource cannot be retrieved by name across all namespaces
:
C:\workspace>kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' | sort
error: a resource cannot be retrieved by name across all namespaces
这是 kubectl 的一个错误,还是这个命令只有 *nix?是否有一个独立于 OS 的命令,用于通过 pod 跨所有命名空间获取容器镜像?
(我在 WSL2 上 运行ning Debian,Windows 10 Enterprise。Docker 使用 WSL2 集成的桌面,K8S 和 minikube。)
来自k8s官方doc:
On Windows, you must double quote any JSONPath template that contains spaces (not single quote as shown above for bash). This in turn means that you must use a single quote or escaped double quote around any literals in the template. For example:
kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.startTime}{'\n'}{end}"
我想这会解决你的问题。