我有一个运行着的kube服务,其中有两个命名端口,如下所示:
$ kubectl get service elasticsearch --output json
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
... stuff that really has nothing to do with my question ...
},
"spec": {
"clusterIP": "10.0.0.174",
"ports": [
{
"name": "http",
"nodePort": 31041,
"port": 9200,
"protocol": "TCP",
"targetPort": 9200
},
{
"name": "transport",
"nodePort": 31987,
"port": 9300,
"protocol": "TCP",
"targetPort": 9300
}
],
"selector": {
"component": "elasticsearch"
},
"sessionAffinity": "None",
"type": "NodePort"
},
"status": {
"loadBalancer": {}
}
}
我正在尝试获取只包含“http”端口的输出:
$ kubectl get service elasticsearch --output jsonpath={.spec.ports[*].nodePort}
31041 31987
除非我按照这里的作弊表http://kubernetes.io/docs/user-guide/kubectl-cheatsheet/中提示的添加测试表达式,否则在名称上添加时会出错。
$ kubectl get service elasticsearch --output jsonpath={.spec.ports[?(@.name=="http")].nodePort}
-bash: syntax error near unexpected token `('