解析 YAML 文件 /etc/prometheus/prometheus.yml:yaml:第 20 行:在此上下文中不允许映射值”
parsing YAML file /etc/prometheus/prometheus.yml: yaml: line 20: mapping values are not allowed in this context"
我正在将一个新的 prometheus pod 部署到一个现有的命名空间我准备了 clusterRole 配置和 configMap 并且一切正常,直到我在 kubernetes 中创建部署。
Pod 创建后崩溃,k8s 日志显示此错误
err="error loading config from \"/etc/prometheus/prometheus.yml\": couldn't load configuration (--config.file=\"/etc/prometheus/prometheus.yml\"): parsing YAML file /etc/prometheus/prometheus.yml: yaml: line 20: mapping values are not allowed in this context"
请问有人知道怎么解决吗?
这是我的部署 YAML 文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: prometheus-deployment
namespace: default
spec:
replicas: 1
template:
metadata:
labels:
app: prometheus-server
spec:
containers:
- name: prometheus
image: prom/prometheus
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
- "--web.console.templates=/usr/share/prometheus/consoles"
ports:
- containerPort: 9090
volumeMounts:
- name: prometheus-config-volume
mountPath: /etc/prometheus/
- name: prometheus-storage-volume
mountPath: /prometheus/
volumes:
- name: prometheus-config-volume
configMap:
defaultMode: 420
name: prometheus-server-conf
- name: prometheus-storage-volume
emptyDir: {}
这里是 k8s 的错误日志
level=info ts=2019-11-08T08:59:43.155Z caller=main.go:296 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:332 msg="Starting Prometheus" version="(version=2.13.1, branch=HEAD, revision=6f92ce56053866194ae5937012c1bec40f1dd1d9)"
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:333 build_context="(go=go1.13.1, user=root@88e419aa1676, date=20191017-13:15:01)"
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:334 host_details="(Linux 4.15.0 #1 SMP Sun Jun 23 23:02:01 PDT 2019 x86_64 prometheus-deployment-6568ff7b6b-jvfsl (none))"
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:335 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:336 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-11-08T08:59:43.161Z caller=main.go:657 msg="Starting TSDB ..."
level=info ts=2019-11-08T08:59:43.161Z caller=web.go:450 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-11-08T08:59:43.191Z caller=head.go:514 component=tsdb msg="replaying WAL, this may take awhile"
level=info ts=2019-11-08T08:59:43.192Z caller=head.go:562 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=1
level=info ts=2019-11-08T08:59:43.192Z caller=head.go:562 component=tsdb msg="WAL segment loaded" segment=1 maxSegment=1
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:672 fs_type=EXT4_SUPER_MAGIC
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:673 msg="TSDB started"
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:743 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:526 msg="Stopping scrape discovery manager..."
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:540 msg="Stopping notify discovery manager..."
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:562 msg="Stopping scrape manager..."
level=info ts=2019-11-08T08:59:43.193Z caller=manager.go:814 component="rule manager" msg="Stopping rule manager..."
level=info ts=2019-11-08T08:59:43.193Z caller=manager.go:820 component="rule manager" msg="Rule manager stopped"
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:536 msg="Notify discovery manager stopped"
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:522 msg="Scrape discovery manager stopped"
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:556 msg="Scrape manager stopped"
level=info ts=2019-11-08T08:59:43.193Z caller=notifier.go:602 component=notifier msg="Stopping notification manager..."
level=info ts=2019-11-08T08:59:43.194Z caller=main.go:727 msg="Notifier manager stopped"
level=error ts=2019-11-08T08:59:43.194Z caller=main.go:736 err="error loading config from \"/etc/prometheus/prometheus.yml\": couldn't load configuration (--config.file=\"/etc/prometheus/prometheus.yml\"): parsing YAML file /etc/prometheus/prometheus.yml: yaml: line 20: mapping values are not allowed in this context"
错误说 /etc/prometheus/prometheus.yml
的内容格式不正确。确保文件包含有效的 YAML 应该可以解决您的问题。
从您的部署来看,prometheus-server-conf
ConfigMap 安装在 /etc/prometheus/
上,因此该 ConfigMap 中的键 prometheus.yml
下的任何内容都可能是罪魁祸首。
我正在将一个新的 prometheus pod 部署到一个现有的命名空间我准备了 clusterRole 配置和 configMap 并且一切正常,直到我在 kubernetes 中创建部署。 Pod 创建后崩溃,k8s 日志显示此错误
err="error loading config from \"/etc/prometheus/prometheus.yml\": couldn't load configuration (--config.file=\"/etc/prometheus/prometheus.yml\"): parsing YAML file /etc/prometheus/prometheus.yml: yaml: line 20: mapping values are not allowed in this context"
请问有人知道怎么解决吗?
这是我的部署 YAML 文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: prometheus-deployment
namespace: default
spec:
replicas: 1
template:
metadata:
labels:
app: prometheus-server
spec:
containers:
- name: prometheus
image: prom/prometheus
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
- "--web.console.templates=/usr/share/prometheus/consoles"
ports:
- containerPort: 9090
volumeMounts:
- name: prometheus-config-volume
mountPath: /etc/prometheus/
- name: prometheus-storage-volume
mountPath: /prometheus/
volumes:
- name: prometheus-config-volume
configMap:
defaultMode: 420
name: prometheus-server-conf
- name: prometheus-storage-volume
emptyDir: {}
这里是 k8s 的错误日志
level=info ts=2019-11-08T08:59:43.155Z caller=main.go:296 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:332 msg="Starting Prometheus" version="(version=2.13.1, branch=HEAD, revision=6f92ce56053866194ae5937012c1bec40f1dd1d9)"
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:333 build_context="(go=go1.13.1, user=root@88e419aa1676, date=20191017-13:15:01)"
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:334 host_details="(Linux 4.15.0 #1 SMP Sun Jun 23 23:02:01 PDT 2019 x86_64 prometheus-deployment-6568ff7b6b-jvfsl (none))"
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:335 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2019-11-08T08:59:43.156Z caller=main.go:336 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-11-08T08:59:43.161Z caller=main.go:657 msg="Starting TSDB ..."
level=info ts=2019-11-08T08:59:43.161Z caller=web.go:450 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-11-08T08:59:43.191Z caller=head.go:514 component=tsdb msg="replaying WAL, this may take awhile"
level=info ts=2019-11-08T08:59:43.192Z caller=head.go:562 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=1
level=info ts=2019-11-08T08:59:43.192Z caller=head.go:562 component=tsdb msg="WAL segment loaded" segment=1 maxSegment=1
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:672 fs_type=EXT4_SUPER_MAGIC
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:673 msg="TSDB started"
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:743 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:526 msg="Stopping scrape discovery manager..."
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:540 msg="Stopping notify discovery manager..."
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:562 msg="Stopping scrape manager..."
level=info ts=2019-11-08T08:59:43.193Z caller=manager.go:814 component="rule manager" msg="Stopping rule manager..."
level=info ts=2019-11-08T08:59:43.193Z caller=manager.go:820 component="rule manager" msg="Rule manager stopped"
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:536 msg="Notify discovery manager stopped"
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:522 msg="Scrape discovery manager stopped"
level=info ts=2019-11-08T08:59:43.193Z caller=main.go:556 msg="Scrape manager stopped"
level=info ts=2019-11-08T08:59:43.193Z caller=notifier.go:602 component=notifier msg="Stopping notification manager..."
level=info ts=2019-11-08T08:59:43.194Z caller=main.go:727 msg="Notifier manager stopped"
level=error ts=2019-11-08T08:59:43.194Z caller=main.go:736 err="error loading config from \"/etc/prometheus/prometheus.yml\": couldn't load configuration (--config.file=\"/etc/prometheus/prometheus.yml\"): parsing YAML file /etc/prometheus/prometheus.yml: yaml: line 20: mapping values are not allowed in this context"
错误说 /etc/prometheus/prometheus.yml
的内容格式不正确。确保文件包含有效的 YAML 应该可以解决您的问题。
从您的部署来看,prometheus-server-conf
ConfigMap 安装在 /etc/prometheus/
上,因此该 ConfigMap 中的键 prometheus.yml
下的任何内容都可能是罪魁祸首。