A developer is creating a ConfigMap from a file named 'app.properties'. The file contains key-value pairs. Which command correctly creates the ConfigMap with keys matching the file content?
Trap 1: kubectl create configmap my-config --from-file=app.properties
Correct. The `--from-file` flag creates a ConfigMap with a single entry where the key is the filename (app.properties) and the value is the entire file content. This matches the requirement that the ConfigMap keys match the file content, meaning the file is stored as one key-value pair with the filename as the key.
Trap 2: kubectl create configmap my-config --from-literal=app.properties
The --from-literal flag is designed to create ConfigMaps from explicit key=value pairs written inline in the command, not from files. Supplying only 'app.properties' without an '=' sign is invalid syntax for this flag, and kubectl will reject it because it cannot parse the input as a literal. Even if it were syntactically accepted, it would simply create a literal key with an empty value, never reading the contents of the app.properties file. Therefore, this command does not satisfy the requirement of storing file content under a key.
Trap 3: cat app.properties | kubectl create configmap my-config…
Incorrect. Piping the file content with `--from-file=-` reads from stdin, but the syntax is incorrect. It would create a ConfigMap with a single key named '-' and the value as the file content, not keys matching the file content.
- A
kubectl create configmap my-config --from-file=app.properties
Why it fails: Correct. The `--from-file` flag creates a ConfigMap with a single entry where the key is the filename (app.properties) and the value is the entire file content. This matches the requirement that the ConfigMap keys match the file content, meaning the file is stored as one key-value pair with the filename as the key.
- B
kubectl create configmap my-config --from-literal=app.properties
Why it fails: The --from-literal flag is designed to create ConfigMaps from explicit key=value pairs written inline in the command, not from files. Supplying only 'app.properties' without an '=' sign is invalid syntax for this flag, and kubectl will reject it because it cannot parse the input as a literal. Even if it were syntactically accepted, it would simply create a literal key with an empty value, never reading the contents of the app.properties file. Therefore, this command does not satisfy the requirement of storing file content under a key.
- C
cat app.properties | kubectl create configmap my-config --from-file=-
Why it fails: Incorrect. Piping the file content with `--from-file=-` reads from stdin, but the syntax is incorrect. It would create a ConfigMap with a single key named '-' and the value as the file content, not keys matching the file content.
- D
kubectl create configmap my-config --from-env-file=app.properties
Incorrect. `--from-env-file` is a valid flag that parses the file as key-value pairs and creates multiple keys in the ConfigMap. This does not satisfy the requirement because it would create separate keys for each line in the file, rather than storing the entire file content under the filename key.