Aman
June 14, 2021, 8:02am
#1
I am trying solve exercises of replication set
root@controlplane:~# cat replicaset-definition-1.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-1
labels:
type: frontend
spec:
template:
metadata:
names: my-app
labels:
tier: frontend
spec:
containers:
- name: nginx
image: nginx
replicas: 2
selector:
matchLabels:
tier: frontend
root@controlplane:~# kubectl apply -f replicaset-definition-1.yaml
error: error validating “replicaset-definition-1.yaml”: error validating data: [ValidationError(ReplicaSet): unknown field “replicas” in io.k8s.api.apps.v1.ReplicaSet, ValidationError(ReplicaSet): unknown field “selector” in io.k8s.api.apps.v1.ReplicaSet, ValidationError(ReplicaSet.spec.template.metadata): unknown field “names” in io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta, ValidationError(ReplicaSet.spec): missing required field “selector” in io.k8s.api.apps.v1.ReplicaSetSpec]; if you choose to ignore these errors, turn validation off with --validate=false
I have created this replica set yaml file it is throwing error can u tell me what is incorrect here
Aman
June 14, 2021, 8:02am
#2
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-1
labels:
type: frontend
spec:
template:
metadata:
names: my-app
labels:
tier: frontend
spec:
containers:
- name: nginx
image: nginx
replicas: 2
selector:
matchLabels:
tier: frontend
Aman
June 14, 2021, 8:04am
#3
i
this my content of replica set file
Aman
June 14, 2021, 9:00am
#4
And after watching solution video i am getting error: error parsing replicaset-definition-1.yaml: error converting YAML to JSON: yaml: line 2: mapping values are not allowed in this context’
Hello, @Aman
There are space required in “replicas” and “selector” fields.
kind:
apiVersion:
metadata:
name:
labels:
spec:
template:
metadata:
name:
labels:
spec:
containers:
- name:
image:
replicas:
selector:
matchLabels:
You can take help of “Solution ” section.
Ayman
June 14, 2021, 3:29pm
#6
try to use these configuration
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-1
spec:
replicas: 2
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: nginx
image: nginx
List item
Ayman
June 14, 2021, 3:30pm
#7
replicas is under spec with 2 space indentation