Courseiva
Services and Networking →mediumMultiple Choice

CKA Services and Networking Practice Question

You need to expose a Service externally using an Ingress. The Ingress controller requires a specific IngressClass. How do you specify the IngressClass in the Ingress resource?

⚠ Common exam trap

It's easy for candidates to confuse the deprecated annotation `kubernetes.io/ingress.class` with the newer `spec.ingressClassName` field, or they invent a non-existent field like `spec.ingressClassRef`, leading them to pick the wrong option.

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

✓

Set spec.ingressClassName: nginx

The `spec.ingressClassName` field is the standard way to specify the IngressClass for an Ingress resource in Kubernetes v1.18+ (GA in v1.22). This field references the name of an IngressClass resource, which defines the controller (e.g., nginx, haproxy) and its configuration. Using this field ensures the Ingress controller selects the correct implementation.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Set spec.class: nginx

    Why it's wrong here

    The Ingress v1 API schema contains no spec.class field; unknown fields are rejected by Kubernetes' API validation, so this would fail to apply. The only class-related field in the Ingress spec is spec.ingressClassName, which must match the metadata.name of an IngressClass resource. Setting spec.class would have no effect even if accepted and is not part of any current networking API version.

  • ✓

    Set spec.ingressClassName: nginx

    Why this is correct

    spec.ingressClassName is the standard field in networking.k8s.io/v1 Ingress that names the IngressClass resource responsible for this Ingress. It is a simple string equal to the .metadata.name of an IngressClass, which in turn declares the controller to use via its spec.controller field. Because this field is part of the formal API, it is the correct, non-deprecated way to expose a service externally with a specific ingress controller.

  • ✗

    Add an annotation: kubernetes.io/ingress.class: nginx

    Why it's wrong here

    This annotation is the legacy mechanism for selecting an ingress controller and is deprecated; Kubernetes docs advise using spec.ingressClassName instead. Since the introduction of the IngressClass resource, this annotation is no longer formally defined and different controllers may treat it inconsistently. Using an annotation for the NGINX class might still work for backward compatibility, but it is not the modern API-driven approach and can conflict when spec.ingressClassName is also set.

  • ✗

    Create an IngressClass resource and reference it via spec.ingressClassRef

    Why it's wrong here

    There is no spec.ingressClassRef field in any version of the Ingress API. An Ingress selects an IngressClass by assigning the class's name to spec.ingressClassName, not by embedding a reference object. While IngressClass is indeed a resource you must create, the binding is done by name string; inventing ingressClassRef would be a schema violation and would not compile against the kubectl validation.

Go deeper

Related to this question

About these practice questions

This CKA question is part of Courseiva's 726-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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 CKA 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 CKA exam.