为什么这个使用 2 个字段选择器和 Powershell 变量 $Node 的 Powershell 命令序列不返回任何 pod?
$Node = "mynode000001"
$pods = (kubectl get pods --field-selector status.phase!=Succeeded,spec.nodeName=$Node -A -o json | ConvertFrom-Json).items
但是 - 这个 Powershell 命令序列确实返回 pods
$Node = "mynode000001"
$command = "kubectl get pods --field-selector status.phase!=Succeeded,spec.nodeName=$Node -A -o json"
$pods = (Invoke-Expression $command | ConvertFrom-Json).items
有没有比预解析命令然后调用它调用表达式更优雅的修复方法?
将问题分解成更小的块,我怀疑分隔字段选择器的逗号破坏了逗号后的 Powershell 变量的解析,但不知道比预解析命令更优雅的解决方案。
这个带有单个字段选择器和 Powershell 变量 $Node 的 Powershell 命令序列返回 K8s pods:
$Node = "mynode000001"
$pods = (kubectl get pods --field-selector spec.nodeName=$Node -A -o json | ConvertFrom-Json).items
这个带有 2 个 kubectl 字段选择器的 Powershell 命令以逗号和硬编码的节点名称分隔返回 pods:
$pods = (kubectl get pods --field-selector status.phase!=Succeeded,spec.nodeName=mynode000001 -A -o json | ConvertFrom-Json).items