kubernetes - 将 YAML 转换为 JSON 时出错:yaml:第 13 行:未找到预期的密钥
问题描述
我正在尝试部署此 yaml 以为 6 个不同的 grok-exporters 部署创建服务,每当我尝试部署此清单时,都会出现以下错误:
error converting YAML to JSON: yaml: line 13: did not find expected key and i can't figure out the issue
yaml 清单:
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
selector:
app: cluster-autoscaler-grok-exporter
- name: evicted-pods-grok-exporter
protocol: TCP
targetPort: 9144
port: 9149
selector:
app: evicted-pods-grok-exporter
- name: flux-hr-grok-exporter
protocol: TCP
targetPort: 9144
port: 9144
selector:
app: flux-hr-grok-exporter
- name: flux-system-grok-exporter
protocol: TCP
targetPort: 9144
port: 9145
selector:
app: flux-system-grok-exporter
- name: ha-proxy-grok-exporter
protocol: TCP
targetPort: 9144
port: 9146
selector:
app: ha-proxy-grok-exporter
- name: spot-requests-grok-exporter
protocol: TCP
targetPort: 9144
port: 9147
selector:
app: spot-requests-grok-exporter
我在这里检查了类似的问题,但不幸的是,我无法让这个脚本工作,所以我非常感谢你的帮助。
谢谢大家!
解决方案
您的问题是spec.selector.app
每个spec.ports
. 应该只有一个选择器,ports 数组应该不间断地列出所有端口
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:
app: spot-requests-grok-exporter
第二步:假设我们想要一个指向多个出口商的单一服务,由不同的部署驱动。并且所有这些出口商都会在同一个端口上侦听,9144
.
除了在您的部署中配置的当前标签之外,我们还将添加一个新标签,在所有这些导出器/部署之间共享。说foo=bar
。
现在,我可以创建一个“导出器”服务,其端点将针对我的所有导出器端口:
apiVersion: v1
kind: Service
metadata:
name: generic-exporter
spec:
type: ClusterIP
ports:
- name: generic-exporter
protocol: TCP
targetPort: 9144
port: 9144
selector:
foo: bar
推荐阅读
- visual-studio - Visual Studio 异常设置搜索快捷方式
- python - 获取用 Python Zelle 图形绘制的图形坐标的颜色
- node.js - 使用 webpack 捆绑库以在浏览器中使用的问题
- security - 如何在我自己的身份验证服务器上使用 OAuth2?
- android - 如何使用确定按钮显示下载完成弹出窗口
- java - 返回当前的 android 布局或屏幕宽度以进行调试
- android - Android:在firebase中将用户注册为管理员
- c++ - Windows Server 2016 上 EnableStatic 的不同行为
- vba - 从工作表 vba 中修剪最后 4 个字符
- javascript - Syncfusion 无法从数据源呈现 Grid 行模板表达式值