Courseiva

CKS Minimize Microservice Vulnerabilities Practice Question

Which command correctly creates a secret from a file named 'config.json'?

⚠ Common exam trap

The CKS exam often tests the confusion between `--from-file` and `--from-literal`, where candidates mistakenly use `--from-literal` with a filename, expecting it to read the file, or confuse `kubectl create secret generic` with `kubectl create configmap` for storing sensitive data.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

kubectl create secret generic my-secret --from-file=config.json

`kubectl create secret generic` with `--from-file=config.json` reads the file content and stores it as a key-value pair in the Secret, where the key defaults to the filename ('config.json') and the value is the raw file data. This is the standard method for creating a generic Secret from a file in Kubernetes.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    kubectl create configmap my-secret --from-file=config.json

    Why it's wrong here

    kubectl create configmap my-secret --from-file=config.json creates a ConfigMap, not a Secret. ConfigMaps store non-sensitive, plaintext configuration data, so this would not protect sensitive information and would violate the intended separation of secrets. To create a Secret from a file, the proper 'kubectl create secret generic' subcommand is required.

  • ✓

    kubectl create secret generic my-secret --from-file=config.json

    Why this is correct

    kubectl create secret generic my-secret --from-file=config.json correctly creates an Opaque Secret named my-secret. The file's basename 'config.json' becomes the data key and its contents become the value; the Secret is then base64-encoded in API responses. This is the standard way to ingest entire files like credentials into Kubernetes without exposing them in the command line.

  • ✗

    kubectl create secret tls my-secret --cert=config.json

    Why it's wrong here

    kubectl create secret tls my-secret --cert=config.json is invalid because the 'tls' subcommand creates a kubernetes.io/tls Secret intended for X.509 certificate/key pairs. It requires both --cert and --key flags pointing to PEM certificate and private key files; a JSON file does not satisfy this, and the command would fail for missing '--key'. For arbitrary file secrets, use 'secret generic' instead.

  • ✗

    kubectl create secret generic my-secret --from-literal=config.json

    Why it's wrong here

    kubectl create secret generic my-secret --from-literal=config.json does not read the file as intended. The --from-literal flag accepts a literal key=value string directly in the command, such as 'password=abc'; passing a bare filename is not a key=value pair and provides no file content. As a result, the secret would contain the literal text string 'config.json' (or be rejected), not the contents of the file.

About these practice questions

One of 845 original CKS practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CKS practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKS exam.