团队,
我有以下输出和 json 查询,但无法检索模式旁边的值。
kubectl get configmap -n kube-system kube-proxy -o json | jq .data
{
"config.conf": "apiVersion: kubeproxy.config.k8s.io/v1alpha1\nbindAddress: 0.0.0.0\nclientConnection:\n acceptContentTypes: \"\"\n burst: 10\n contentType: application/vnd.kubernetes.protobuf\n kubeconfig: /var/lib/kube-proxy/kubeconfig.conf\n qps: 5\nclusterCIDR: 10.233.64.0/18\nconfigSyncPeriod: 15m0s\nconntrack:\n max: null\n maxPerCore: 32768\n min: 131072\n tcpCloseWaitTimeout: 1h0m0s\n tcpEstablishedTimeout: 24h0m0s\nenableProfiling: false\nhealthzBindAddress: 0.0.0.0:10256\nhostnameOverride: hosta\niptables:\n masqueradeAll: false\n masqueradeBit: 14\n minSyncPeriod: 0s\n syncPeriod: 30s\nipvs:\n excludeCIDRs: null\n minSyncPeriod: 0s\n scheduler: rr\n syncPeriod: 30s\nkind: KubeProxyConfiguration\nmetricsBindAddress: 127.0.0.1:10249\nmode: iptables\nnodePortAddresses: []\noomScoreAdj: -999\nportRange: \"\"\nresourceContainer: /kube-proxy\nudpIdleTimeout: 250ms",
"kubeconfig.conf": "apiVersion: v1\nkind: Config\nclusters:\n- cluster:\n certificate-authority: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt\n server: https://127.0.0.1:6443\n name: default\ncontexts:\n- context:\n cluster: default\n namespace: default\n user: default\n name: default\ncurrent-context: default\nusers:\n- name: default\n user:\n tokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token"
}
kubectl get configmap -n kube-system kube-proxy -o json | jq .data.\"config.conf\".mode
jq: error (at <stdin>:19): Cannot index string with string "mode"
另外,有没有办法使用 awk 来拉它?
试过:
kubectl get configmap -n kube-system kube-proxy -o json | jq -r '.["config.conf"] | splits("\n") | select( test("^mode") ) | [splits(": *")] | .[1]'
jq: error (at <stdin>:19): null (null) cannot be matched, as it is not a string