Pregunta de Kubernetes #019e3a4f
Which of the following options include only mandatory fields to create a Kubernetes object using a YAML file?
apiVersion, template, kind, status
apiVersion, metadata, status, spec
apiVersion, template, kind, spec
apiVersion, metadata, kind, spec
Explicación Oficial / Explicaciones de la Comunidad
In Kubernetes, every object definition in a YAML file must include four mandatory fields: apiVersion, kind, metadata, and spec. The apiVersion specifies the API version used to create the object (e.g., v1, apps/v1). kind defines the type of object (e.g., Pod, Deployment). metadata contains identifying information such as name and namespace. spec describes the desired state of the object (e.g., containers, replicas). Fields like template are nested within spec for certain objects (e.g., Deployments) but are not top-level mandatory fields. status is a read-only field populated by Kubernetes after creation and is not part of the user-provided YAML. Therefore, the correct set of mandatory fields is apiVersion, metadata, kind, and spec.
How it Works
When you create a Kubernetes object via kubectl apply -f file.yaml, the API server validates the YAML against the schema for the given apiVersion and kind. The metadata field must include at least a name (and optionally namespace). The spec field contains the desired configuration; its contents vary by object type. Without these four fields, the API server will reject the request.
Why the Correct Value is Right
The combination apiVersion, metadata, kind, and spec includes all top-level mandatory fields. For example, a minimal Pod YAML:
This YAML is valid and can be submitted.
Why the Incorrect Values are Wrong
apiVersion,template,kind,status:templateis not a top-level field; it is nested insidespecfor controllers like Deployments.statusis read-only and not user-provided.apiVersion,metadata,status,spec:statusis not a mandatory input field; it is automatically generated by Kubernetes.apiVersion,template,kind,spec:templateis not a top-level mandatory field; it belongs insidespecfor certain objects. Also,metadatais missing, which is required for all objects.