You need to enable JavaScript to run this app. 部署grok-exporter对应Service YAML报错转JSON第13行未找到预期key
优惠活动
大模型
产品
解决方案
定价
更多

部署grok-exporter对应Service YAML报错转JSON第13行未找到预期key

问题根因

你当前的YAML配置完全不符合Kubernetes Service的API结构规范,两处核心错误直接触发语法报错:

  • 单个Service资源只能配置全局唯一的selector字段,用于匹配后端Pod标签,不支持为每个端口单独绑定selector
  • 你将selector字段错误插入到了ports数组的条目之间,破坏了YAML的层级结构,直接导致解析器在第13行无法识别合法的配置key

解决方案

根据你的使用场景二选一即可:

场景1:每个grok-exporter独立暴露访问入口

需要拆分创建6个独立的Service资源,不同资源之间用---分隔,示例配置如下:

# cluster-autoscaler-grok-exporter 对应Service
apiVersion: v1
kind: Service
metadata:
  name: cluster-autoscaler-grok-exporter-svc
spec:
  type: ClusterIP
  ports:
  - name: metrics
    protocol: TCP
    targetPort: 9144
    port: 9148
  selector:
    app: cluster-autoscaler-grok-exporter
---
# evicted-pods-grok-exporter 对应Service
apiVersion: v1
kind: Service
metadata:
  name: evicted-pods-grok-exporter-svc
spec:
  type: ClusterIP
  ports:
  - name: metrics
    protocol: TCP
    targetPort: 9144
    port: 9149
  selector:
    app: evicted-pods-grok-exporter
# 剩余4个grok-exporter按照上述格式依次补充即可

场景2:所有grok-exporter共用一个统一访问入口

首先给6个grok-exporter Deployment的Pod模板添加同一个公共标签,例如app.kubernetes.io/name: grok-exporter,再使用如下Service配置:

apiVersion: v1
kind: Service
metadata:
  name: grok-exporter-centralized-service
spec:
  type: ClusterIP
  ports:
  - name: cluster-autoscaler-grok-exporter-metrics
    protocol: TCP
    targetPort: 9144
    port: 9148
  - name: evicted-pods-grok-exporter
    protocol: TCP
    targetPort: 9144
    port: 9149
  - name: flux-hr-grok-exporter
    protocol: TCP
    targetPort: 9144
    port: 9144
  - name: flux-system-grok-exporter
    protocol: TCP
    targetPort: 9144
    port: 9145
  - name: ha-proxy-grok-exporter
    protocol: TCP
    targetPort: 9144
    port: 9146
  - name: spot-requests-grok-exporter
    protocol: TCP
    targetPort: 9144
    port: 9147
  # 全局唯一selector,匹配所有grok-exporter的公共标签
  selector:
    app.kubernetes.io/name: grok-exporter

校验小技巧

部署前可以先执行kubectl apply --dry-run=client -f <配置文件名.yaml>提前校验配置语法,避免直接部署报错。

内容的提问来源于stack exchange,提问作者doksha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.14 22:57:00