Bird
Raised Fist0
Kubernetesdevops~20 mins

Secret types (Opaque, docker-registry, TLS) in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Secret Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of creating an Opaque secret with kubectl
What is the output of the following command when creating an Opaque secret named mysecret with a literal key-value pair username=admin?
Kubernetes
kubectl create secret generic mysecret --from-literal=username=admin
AWarning: secret/mysecret already exists
Bsecret/mysecret created
CError from server (Forbidden): secrets is forbidden: User "system:anonymous" cannot create resource "secrets"
Dsecret/mysecret deleted
Attempts:
2 left
💡 Hint
Think about the normal success message when creating a secret with kubectl.
🧠 Conceptual
intermediate
1:30remaining
Purpose of docker-registry secret type
What is the main purpose of a Kubernetes secret of type kubernetes.io/dockerconfigjson (docker-registry)?
ATo store Docker registry credentials for pulling private images
BTo store SSH keys for accessing remote servers
CTo store generic key-value pairs for application configuration
DTo store TLS certificates for secure communication
Attempts:
2 left
💡 Hint
Think about what is needed to pull images from private Docker registries.
❓ Configuration
advanced
2:00remaining
Correct YAML for TLS secret
Which YAML snippet correctly defines a TLS secret named mytlssecret with certificate and key files?
A
apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
  name: mytlssecret
data:
  tls.crt: <base64-encoded-cert>
  tls.key: <base64-encoded-key>
B
apiVersion: v1
kind: Secret
type: Opaque
metadata:
  name: mytlssecret
stringData:
  tls.crt: <plain-cert>
  tls.key: <plain-key>
C
apiVersion: v1
kind: ConfigMap
metadata:
  name: mytlssecret
data:
  tls.crt: <plain-cert>
  tls.key: <plain-key>
D
apiVersion: v1
kind: Secret
type: kubernetes.io/dockerconfigjson
metadata:
  name: mytlssecret
data:
  .dockerconfigjson: <base64-encoded-json>
Attempts:
2 left
💡 Hint
TLS secrets require a specific type and base64 encoded data keys named tls.crt and tls.key.
❓ Troubleshoot
advanced
2:00remaining
Error when pulling image with docker-registry secret
You created a docker-registry secret and referenced it in your Pod spec, but the Pod fails to pull the private image with an 'unauthorized' error. What is the most likely cause?
AThe secret is missing the key '.dockerconfigjson' with correct JSON content
BThe TLS certificate in the secret expired
CThe secret type is set to 'Opaque' instead of 'kubernetes.io/dockerconfigjson'
DThe Pod spec does not reference the secret under imagePullSecrets
Attempts:
2 left
💡 Hint
Check if the Pod knows to use the secret for pulling images.
✅ Best Practice
expert
2:30remaining
Best practice for managing TLS secrets in Kubernetes
Which practice is considered best for managing TLS secrets securely in Kubernetes clusters?
AUse Opaque secrets with base64 encoded TLS data and restrict RBAC access
BStore TLS secrets as plain text ConfigMaps for easy access
CUse kubernetes.io/tls secret type and automate certificate renewal with cert-manager
DEmbed TLS certificates directly in Pod specs as environment variables
Attempts:
2 left
💡 Hint
Think about automation and security combined for TLS management.

Practice

(1/5)
1. Which Kubernetes secret type is best suited for storing general sensitive data like passwords or tokens?
easy
A. Opaque
B. docker-registry
C. TLS
D. ConfigMap

Solution

  1. Step 1: Understand secret types

    Opaque secrets are designed to store arbitrary user-defined data such as passwords or tokens.
  2. Step 2: Compare with other types

    docker-registry is for Docker credentials, TLS is for certificates, and ConfigMap is not a secret type.
  3. Final Answer:

    Opaque -> Option A
  4. Quick Check:

    General sensitive data = Opaque [OK]
Hint: Opaque = general secret data, docker-registry = Docker creds [OK]
Common Mistakes:
  • Confusing TLS secrets with general data storage
  • Using docker-registry for non-Docker secrets
  • Thinking ConfigMap is a secret type
2. Which kubectl command correctly creates a docker-registry secret named myregistrykey with username user1 and password pass123?
easy
A. kubectl create secret docker-registry myregistrykey --docker-server=https://myregistry.com --docker-username=user1 --docker-password=pass123
B. kubectl create secret generic myregistrykey --docker-username=user1 --docker-password=pass123
C. kubectl create secret tls myregistrykey --docker-username=user1 --docker-password=pass123
D. kubectl create secret docker-registry myregistrykey --username=user1 --password=pass123

Solution

  1. Step 1: Identify correct secret type and flags

    docker-registry secrets require the type 'docker-registry' and flags --docker-server, --docker-username and --docker-password.
  2. Step 2: Check command syntax

    kubectl create secret docker-registry myregistrykey --docker-server=https://myregistry.com --docker-username=user1 --docker-password=pass123 uses correct type and flags; others use wrong types or flag names.
  3. Final Answer:

    kubectl create secret docker-registry myregistrykey --docker-server=https://myregistry.com --docker-username=user1 --docker-password=pass123 -> Option A
  4. Quick Check:

    docker-registry + --docker-server/--docker-username/password = correct [OK]
Hint: Use --docker-server, --docker-username and --docker-password with docker-registry type [OK]
Common Mistakes:
  • Using generic secret type for docker-registry secrets
  • Wrong flag names like --username instead of --docker-username
  • Using TLS secret type for docker credentials
3. Given the command kubectl create secret tls mytlssecret --cert=cert.pem --key=key.pem, what will be the type of the created secret?
medium
A. Opaque
B. docker-registry
C. TLS
D. generic

Solution

  1. Step 1: Analyze the command

    The command uses 'create secret tls' with certificate and key files specified.
  2. Step 2: Match secret type

    Secrets created with 'tls' type store TLS certificates and keys, so the type is TLS.
  3. Final Answer:

    TLS -> Option C
  4. Quick Check:

    kubectl create secret tls = TLS type secret [OK]
Hint: TLS secrets use 'kubectl create secret tls' with cert and key [OK]
Common Mistakes:
  • Assuming TLS secrets are Opaque
  • Confusing generic secret type with TLS
  • Not specifying cert and key files properly
4. You run kubectl create secret tls mytlssecret --cert=cert.pem but get an error. What is the likely cause?
medium
A. Using wrong secret type, should be opaque
B. Missing --key flag with private key file
C. Certificate file is empty
D. Secret name contains invalid characters

Solution

  1. Step 1: Check required flags for TLS secret

    Creating TLS secrets requires both --cert and --key flags to specify certificate and private key files.
  2. Step 2: Identify missing flag

    The command only has --cert but lacks --key, causing the error.
  3. Final Answer:

    Missing --key flag with private key file -> Option B
  4. Quick Check:

    Both --cert and --key required for TLS secret [OK]
Hint: TLS secrets need both --cert and --key flags [OK]
Common Mistakes:
  • Omitting the --key flag when creating TLS secrets
  • Using opaque type instead of TLS for certs
  • Assuming secret name format causes error
5. You want to pull images from a private Docker registry in your Kubernetes cluster. Which secret type should you create and how should you use it in a Pod spec?
hard
A. Create a TLS secret and add it to the Pod's environment variables
B. Create an opaque secret and mount it as a volume in the Pod
C. Create a generic secret and specify it in the Pod's volumes section
D. Create a docker-registry secret and reference it in imagePullSecrets of the Pod

Solution

  1. Step 1: Identify secret type for private Docker registry

    docker-registry secret stores Docker credentials for private registries.
  2. Step 2: Use secret in Pod spec

    To allow image pull, reference the secret in the Pod's imagePullSecrets field.
  3. Final Answer:

    Create a docker-registry secret and reference it in imagePullSecrets of the Pod -> Option D
  4. Quick Check:

    Private Docker registry = docker-registry secret + imagePullSecrets [OK]
Hint: Use docker-registry secret with imagePullSecrets in Pod spec [OK]
Common Mistakes:
  • Mounting docker-registry secrets as volumes instead of imagePullSecrets
  • Using opaque or TLS secrets for Docker registry auth
  • Not referencing the secret in Pod spec
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard