CKA YAML Configuration 2 — Questions and Answers
Question 1: Which YAML syntax correctly defines a multi-line string that preserves newlines in a Kubernetes ConfigMap?
- key: 'line1\nline2'
- key: | line1 line2 (Correct answer)
- key: >- line1 line2
- key: [line1, line2]
Correct answer: key: | line1 line2
The literal block scalar `|` preserves newlines exactly as written, making it ideal for multi-line config values.
Question 2: In a Kubernetes Pod spec, what is the correct YAML field to set an environment variable from a ConfigMap key?
- env.configMap
- envFrom.configMapRef
- env[].valueFrom.configMapKeyRef (Correct answer)
- env[].configMapKeyRef
Correct answer: env[].valueFrom.configMapKeyRef
The `env[].valueFrom.configMapKeyRef` field references a specific key from a ConfigMap to inject as an environment variable.
Question 3: What does the `---` separator in a YAML file signify when used in Kubernetes manifests?
- End of file
- Start of a comment block
- Separation between multiple Kubernetes resource definitions (Correct answer)
- Separation between spec and metadata
Correct answer: Separation between multiple Kubernetes resource definitions
The `---` document separator allows multiple Kubernetes resource objects to be defined in a single YAML file.
Question 4: Which YAML anchor/alias feature is valid in Kubernetes manifests processed by kubectl?
- Anchors and aliases are fully supported and recommended
- Anchors (&) and aliases (*) are supported by kubectl's YAML parser (Correct answer)
- Anchors are supported but aliases are not
- Neither anchors nor aliases are supported by kubectl
Correct answer: Anchors (&) and aliases (*) are supported by kubectl's YAML parser
kubectl uses a YAML parser that supports anchors (&) and aliases (*), allowing reuse of repeated configuration blocks.
Question 5: A Deployment YAML has `replicas: '3'` (as a string). What will happen when applied?
- Kubernetes will automatically coerce the string to an integer
- kubectl will reject the manifest with a type validation error (Correct answer)
- The Deployment will be created with 0 replicas
- The Deployment will be created with 1 replica
Correct answer: kubectl will reject the manifest with a type validation error
Kubernetes API validation enforces strict types; `replicas` must be an integer, so a quoted string value will cause a validation error.
Question 6: What is the correct YAML indentation for a container's `resources.limits` block in a Pod spec?
- resources and limits at the same indentation level under the container
- limits nested under resources, which is nested under the container entry (Correct answer)
- limits defined at the Pod spec level, not inside containers
- resources defined at spec level with limits as a sibling of containers
Correct answer: limits nested under resources, which is nested under the container entry
The `resources` field belongs to each container entry, with `limits` and `requests` as child keys nested beneath it.
Question 7: How do you correctly specify an empty value for a key in a Kubernetes YAML manifest?
- key: NULL
- key: undefined
- key: null (Correct answer)
- key: ""
Correct answer: key: null
In YAML, `null` (lowercase) is the correct null literal; Kubernetes uses this to represent explicitly unset optional fields.
Which YAML syntax correctly defines a multi-line string that preserves newlines in a Kubernetes ConfigMap?