error converting YAML to JSON, did not find expected key kubernetes
Solution 1:
yamllint package is useful to debug and find this kind of errors, just do yamllint filename
and it will list the possible problems it finds. Install via your distro package manager (usually recommended if available) or via the below npm install command (it will install globally)
npm install -g yaml-lint
Thanks to Kyle VG for the npm command
Solution 2:
The overall file looks good. There are some issues with indentation.
YAML file
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
spec:
volumes:
- name: nginx-config
configMap:
name: nginx-config
- name: php-config
configMap:
name: php-config
containers:
- image: php-fpm:7.2
name: php
ports:
- containerPort: 9000
volumeMounts:
- name: persistent-storage
# looks like indentation issue here
mountPath: /var/www/data
- name: php-config
# looks like indentation issue here
mountPath: /usr/local/etc/php-fpm.d/www.conf
subPath: www.conf
- image: nginx:latest
name: nginx
- containerPort: 80
volumeMounts:
- name: persistent-storage
mountPath: /var/www/data
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: nfs-pvc
Solution 3:
Following higuita
's answer you can lint your yaml and check for errors without installing a module in your machine using npx. I prefer this approach for commands that I do not intend to use often. NPX downloads the package, executes the command and remove the package when finishes.
npx yaml-lint yamllint file_name