I'm a novice regarding YAML format and kubernetes.
The following is a dep_prom.yml file.
--- apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: name: prometheus-deployment name: prometheus #namespace: prometheus spec: replicas: 1 template: metadata: labels: app: prometheus spec: containers: - image: prom/prometheus:master name: prometheus command: - "/bin/prometheus" args: - "-config.file=/etc/prometheus/prometheus.yml" - "-storage.local.path=/prometheus" - "-storage.local.retention=24h" ports: - containerPort: 9090 protocol: TCP volumeMounts: - mountPath: "/prometheus" name: data - mountPath: "/etc/prometheus" name: config-volume resources: requests: cpu: 100m memory: 100Mi limits: cpu: 500m memory: 2500Mi volumes: - name: data hostPath: path: /data/prometheus - name: config-volume configMap: name: prometheus nodeSelector: westporch-kubeminion-1 kubernetes.io/hostname: 10.0.24.52 ---
However... When I executed kubectl create -f dep_prom.yml
error: error converting YAML to JSON: yaml: line 47: mapping values are not allowed in this context
Line 47 is nodeSelector: westporch-kubeminion-1
I think that YAML file format is normal.
What is causing this error?
Map Values() Method in Java With Examples Map Values() method returns the Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa.
YAML syntaxYAML has features that come from Perl, C, XML, HTML, and other programming languages. YAML is also a superset of JSON, so JSON files are valid in YAML. YAML uses Python-style indentation to indicate nesting. Tab characters are not allowed, so whitespaces are used instead.
YAML is a digestible data serialization language often used to create configuration files with any programming language. Designed for human interaction, YAML is a strict superset of JSON, another data serialization language. But because it's a strict superset, it can do everything that JSON can and more.
Or like the error says "mapping values are not allowed in this context". It means that the keys/values you have used in the yaml, may be syntactically right but not semantically.
1). A syntax error (in your case it is not) in the yaml file. 2). Or like the error says "mapping values are not allowed in this context". It means that the keys/values you have used in the yaml, may be syntactically right but not semantically.
Because these are both key-value pair lines (i.e. item pairs of a block-style mapping) instead of but it might be that nodeSelector needs a mapping as argument instead of the scalar westporch-kubeminion-1 it has now.
You indicate you think the YAML format is normal, but it is not. This is a YAML error caused by the line at the end of the first document, starting with kubernetes.io/hostname
being indented relative to the one before it. Because these are both key-value pair lines (i.e. item pairs of a block-style mapping) instead of
nodeSelector: westporch-kubeminion-1 kubernetes.io/hostname: 10.0.24.52
you either need to do:
nodeSelector: westporch-kubeminion-1 kubernetes.io/hostname: 10.0.24.52
but it might be that nodeSelector
needs a mapping as argument instead of the scalar westporch-kubeminion-1
it has now.
nodeSelector: kubernetes.io/hostname: 10.0.24.52
This error might mask a second one in the file, depending on how lenient kubernetes is. The ---
is the end-of-directives marker and since the directives are optional it can occur at the start of a YAML document. The one at the bottom of your example indicates the start of a new document. Once you address the first error, you might get a warning about single documents based on that. (The end-of-document marker consists of three dots: ...
at the beginning of a line followed by whitespace.
Of course any changes you make should confirm to what kubernetes is expecting, but the above stream is clearly non-valid as YAML in itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With