I am doing a lab about Kubernetes. I have created the YAML file, but when I am trying to deploy it in a shell, it shows me this error:
error: error parsing mongodb-deployment.yaml: error converting YAML to JSON: yaml: line 27: did not find expected key
This is the YAML file for MongoDB for Kubernetes:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFROM:
secretKeyRef:
name: mongodb-secret
key: mongo-root-username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFROM:
secretKeyRef:
name: mongodb-secret
key: mongo-root-password
valueFROM
is changed to valueFrom
. Also, template
was under selector
, so I moved template
out of selector
, so it would be under spec
.
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template: #this and all the following lines are moved 2 places left.
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-root-username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-root-password