Bird
0
0

You want to create a Helm chart that conditionally creates a Service only if service.enabled is true in values.yaml. Which template snippet correctly implements this?

hard📝 Workflow Q8 of 15
Kubernetes - Helm Package Manager
You want to create a Helm chart that conditionally creates a Service only if service.enabled is true in values.yaml. Which template snippet correctly implements this?
A{{- if .service.enabled }} apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - port: 80 {{- end }}
B{{- with .Values.service.enabled }} apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - port: 80 {{- end }}
C{{- if .Values.service.enabled }} apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - port: 80 {{- end }}
D{{- if .Values.service.enabled == true }} apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - port: 80 {{- end }}
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct value reference and conditional

    Use .Values.service.enabled with if to conditionally render.
  2. Step 2: Evaluate options

    {{- if .Values.service.enabled }} apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - port: 80 {{- end }} uses correct syntax; {{- with .Values.service.enabled }} apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - port: 80 {{- end }} uses with which changes context; {{- if .service.enabled }} apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - port: 80 {{- end }} misses .Values; {{- if .Values.service.enabled == true }} apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - port: 80 {{- end }} uses invalid == operator.
  3. Final Answer:

    {{- if .Values.service.enabled }} -> Option C
  4. Quick Check:

    Use if with .Values for conditionals [OK]
Quick Trick: Use if .Values.key for conditional template blocks [OK]
Common Mistakes:
  • Omitting .Values prefix
  • Using with which changes context unexpectedly
  • Overcomplicating condition with eq

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes