tron40a
December 19, 2024, 7:33pm
1
Hey everyone, really new to Kubernetes and need a little help. Have anyone of you come across this?
Error when trying to apply ConfigMap to deployment yaml.
error when creating “httpd-deployment-datacenter.yaml”: Deployment in version “v1” cannot be handled as a Deployment: strict decoding error: unknown field “spec.template.spec.spec”
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-deployment-datacenter
spec:
selector:
matchLabels:
app: httpd_app_datacenter
replicas: 4
template:
metadata:
labels:
app: httpd_app_datacenter
spec:
containers:
- name: httpd-container-datacenter
image: httpd:latest
ports:
- containerPort: 80
spec:
volumeMounts:
- name: httpd-configmap-datacenter
mountPath: /usr/share/nginx/html/
volumes:
- name: httpd-configmap-datacenter
thockin
December 19, 2024, 8:00pm
2
Please put your YAML in a code block (triple-backquotes) – nobody can make sense of it without whitespace.
1 Like
tron40a
December 19, 2024, 8:13pm
4
Hi thockin, sorry, but not sure how to do this.
tron40a
December 19, 2024, 8:18pm
5
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-deployment-datacenter
spec:
selector:
matchLabels:
app: httpd_app_datacenter
replicas: 4
template:
metadata:
labels:
app: httpd_app_datacenter
spec:
containers:
- name: httpd-container-datacenter
image: httpd:latest
ports:
- containerPort: 80
spec:
volumeMounts:
- name: httpd-configmap-datacenter
mountPath: /usr/share/nginx/html/
volumes:
- name: httpd-configmap-datacenter
thockin
December 19, 2024, 8:30pm
7
Yeah, you have spec
under spec
- this is just incorrect yaml.
kind: Deployment
metadata:
name: httpd-deployment-datacenter
spec:
selector:
matchLabels:
app: httpd_app_datacenter
replicas: 4
template:
metadata:
labels:
app: httpd_app_datacenter
spec:
containers:
- name: httpd-container-datacenter
image: httpd:latest
ports:
- containerPort: 80
volumeMounts:
- name: httpd-configmap-datacenter
mountPath: /usr/share/nginx/html/
volumes:
- name: httpd-configmap-datacenter
tron40a
December 19, 2024, 8:34pm
8
I had it without the 1st time and got the following error.
=Error parsing httpd-deployment-datacenter.yaml: error converting YAML to JSON. Line 19: did not find expected key.
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-deployment-datacenter
spec:
selector:
matchLabels:
app: httpd_app_datacenter
replicas: 4
template:
metadata:
labels:
app: httpd_app_datacenter
spec:
containers:
- name: httpd-container-datacenter
image: httpd:latest
ports:
- containerPort: 80
volumeMounts:
- name: httpd-configmap-datacenter
mountPath: /usr/share/nginx/html/
volumes:
- name: httpd-configmap-datacenter
tron40a
December 19, 2024, 8:43pm
9
I copied your updated yaml and got the following error, but there is the “-” that you entered, so not sure why it’s not seeing it.
error: error parsing httpd-deployment-datacenter.yaml: error converting YAML to JSON: yaml: line 18: did not find expected ‘-’ indicator
thockin
December 19, 2024, 9:07pm
10
Yours is still messed up - please do look at the API docs. Pasting mine into a YAML-to-JSON converter shows I mistyped some whitespace, too. The below passes that test, but I didn’t try to run it.
kind: Deployment
metadata:
name: httpd-deployment-datacenter
spec:
selector:
matchLabels:
app: httpd_app_datacenter
replicas: 4
template:
metadata:
labels:
app: httpd_app_datacenter
spec:
containers:
- name: httpd-container-datacenter
image: httpd:latest
ports:
- containerPort: 80
volumeMounts:
- name: httpd-configmap-datacenter
mountPath: /usr/share/nginx/html/
volumes:
- name: httpd-configmap-datacenter
tron40a
December 19, 2024, 9:13pm
11
This one worked! Thank a bunch for all of your help. Just getting started in Kubernetes, day 2 actually. Will read up more.