Questão de Kubernetes Fundamentals #019e3a4f
What fields must exist in any Kubernetes object (e.g. YAML) file?
apiVersion, kind, metadata
kind, namespace, data
apiVersion, metadata, namespace
kind, metadata, data
Explicação Oficial / Explicações da Comunidade
Every Kubernetes object definition in YAML or JSON must include three required fields: apiVersion, kind, and metadata. The apiVersion field specifies the API version used for the object (e.g., v1, apps/v1). The kind field identifies the type of object (e.g., Pod, Deployment, Service). The metadata field contains data that uniquely identifies the object, such as name, namespace, labels, and annotations. Without these three fields, the Kubernetes API server cannot process the object definition.
How it Works
When you submit a Kubernetes object manifest to the API server, the server validates the manifest against the expected schema. The apiVersion tells the server which API group and version to use for deserialization. The kind tells the server which resource type to create or modify. The metadata provides the identity and optional descriptive information. All other fields, such as spec or data, are specific to the object kind and are not universally required.
Why the Correct Value is Right
The combination apiVersion, kind, and metadata is the minimal set required by the Kubernetes API. For example, a simple Pod manifest must include:
Without any of these, the API server returns an error.
Why the Incorrect Values are Wrong
- The combination
kind,namespace,datais incorrect becausenamespaceis optional (it defaults todefaultif omitted) anddatais not a required field for all objects (it is specific to objects like ConfigMaps and Secrets). - The combination
apiVersion,metadata,namespaceis incorrect becausekindis missing; the API server cannot determine the object type without it. - The combination
kind,metadata,datais incorrect becauseapiVersionis missing; the API server cannot determine which API version to use for deserialization, anddatais not universally required.