Kubernetes Troubleshooting issue

thor@jump_host ~$ kubectl create -f /home/thor/mysql_deployment.yml
persistentvolume/mysql-pv created
persistentvolumeclaim/mysql-pv-claim created
error: error parsing /home/thor/mysql_deployment.yml: error converting YAML to JSON: yaml: line 49: did not find expected β€˜-’ indicator

I am unable find the error.Kindly let me know what mistake I have done.


apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
labels:
type: local
spec:
storageClassName: standard
capacity:
storage: 250Mi
accessModes:
- ReadWriteOnce
hostPath:
path: β€œ/mnt/data”


apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: mysql-app
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 250Mi


apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
labels:
app: mysql-app
spec:
selector:
matchLabels:
app: mysql-app
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql-app
tier: mysql
spec:
containers:
- image: mysql:5.6
name: mysql-container
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-root-pass
key: password
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
name: mysql-db-url
key: database
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql-user-pass
key: username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-user-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim


apiVersion: v1
kind: Service
metadata:
name: mysql
labels:
app: mysql-app
spec:
type: NodePort
ports:
- targetPort: 3306
port: 3306
nodePort: 30011
selector:
app: mysql-app
tier: mysql

Hi @nithyaks,
Please share it in the correct format. Use the code block.

FYI

Regards,

Hi @nithyaks,

The meaning of the error that you have commented on is that there is a problem on line 49 of mysql_deployment.yml where an expected dash indicator (- ) is missing.

Please use this code for mysql_deployment.yml

Here are some things to keep in mind while working on YAML files include: Indentation, Spacing, Syntax, Structure, Quoting, etc.

In this case, volumeMounts is having list type containing the item mountPath which is represented by the - indicator so failing the proper space or indentation will result in a syntax error.

Hope this helps, have a good day ahead!

Regards,
Sumit

Thanks for the help. I fixed the indentation and now able to complete the task.

1 Like