Kubernetes
medium

Pregunta de Kubernetes #019e3a4f

Enunciado de la Pregunta
Kubernetes
#kubernetes
#yaml
#api-version
#metadata
#kind
#spec
Medio

Which of the following options include only mandatory fields to create a Kubernetes object using a YAML file?

A

apiVersion, template, kind, status

B

apiVersion, metadata, status, spec

C

apiVersion, template, kind, spec

D

apiVersion, metadata, kind, spec

Correcto

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:

Carregando bloco de código...

This YAML is valid and can be submitted.

Why the Incorrect Values are Wrong

  • apiVersion, template, kind, status: template is not a top-level field; it is nested inside spec for controllers like Deployments. status is read-only and not user-provided.
  • apiVersion, metadata, status, spec: status is not a mandatory input field; it is automatically generated by Kubernetes.
  • apiVersion, template, kind, spec: template is not a top-level mandatory field; it belongs inside spec for certain objects. Also, metadata is missing, which is required for all objects.