CKA · Question #50
CKA Question #50: Real Exam Question with Answer & Explanation
The correct approach involves creating a YAML file for a Kubernetes Ingress resource with the specified name and namespace, including a minimal valid specification, and then applying this file using the kubectl apply command within the provided web terminal.
Question
Create a new Ingress resource as follows: - Name: echo - Namespace: sound-repeater
Explanation
The correct approach involves creating a YAML file for a Kubernetes Ingress resource with the specified name and namespace, including a minimal valid specification, and then applying this file using the kubectl apply command within the provided web terminal.
Approach. The task requires creating a new Kubernetes Ingress resource with a specific name ('echo') and namespace ('sound-repeater'). Since the provided images show a web terminal, the interaction must occur within this command-line environment.
-
Open a text editor: The test-taker should open a text editor within the terminal to create a new YAML file for the Ingress resource. A common choice is
viornano. For example:vi echo-ingress.yaml. -
Define the Ingress YAML: The YAML file must include the
apiVersion,kind,metadata(withnameandnamespace), and a minimal validspecfor an Ingress. Since the question only provides the name and namespace, a common practice in exams is to infer a basic, functionalspec(e.g., pointing to a common backend service on a standard port). A typical minimal functional Ingress that would validate against the Kubernetes API is as follows:apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: echo namespace: sound-repeater spec: rules: - http: paths: - path: / pathType: Prefix backend: service: name: echo-service # A placeholder service name, implied by 'echo' ingress name port: number: 80 # Common HTTP port -
Save the file: After entering the YAML content, save the file and exit the editor (e.g., in
vi, pressEsc, type:wq, and pressEnter). -
Apply the resource: Use the
kubectl applycommand to create the Ingress resource from the YAML file:kubectl apply -f echo-ingress.yaml.
This sequence ensures that a valid Ingress resource conforming to the specified requirements is created in the Kubernetes cluster.
Common mistakes.
- common_mistake. 1. Trying to modify the displayed
spec_deployment.yaml: The Deployment YAML shown in the exhibit is unrelated to the task. Attempting to edit this file or derive an Ingress from it would be incorrect.
- Incorrect Ingress YAML syntax: Forgetting required fields like
apiVersion: networking.k8s.io/v1,kind: Ingress, or incorrect indentation will lead to validation errors. - Omitting the
specsection or providing an invalidspec: An Ingress resource (specificallynetworking.k8s.io/v1) requires eitherspec.rulesorspec.defaultBackendto be valid. Simply providingapiVersion,kind, andmetadatawill result in a validation error ('Ingress.networking.k8s.io "echo" is invalid: [spec: Required value, spec.rules: Required value]'). - Using
kubectl create ingressdirectly: Thekubectl create ingresscommand is not designed to directly create an Ingress resource with detailed rules via command-line flags. Whilekubectl createcan generate basic YAML for some resources using--dry-run=client -o yaml, it doesn't provide a ready-to-use Ingress manifest with rules, making manual YAML creation or editing a generated template the most reliable approach. - Incorrect namespace or name: Typos in
name: echoornamespace: sound-repeaterwould result in the resource not being created as specified.
Concept tested. 1. Kubernetes Ingress Resource: Understanding the purpose, structure, and required fields of an Ingress resource (apiVersion, kind, metadata, spec, rules, backend).
2. YAML Manifests: Proficiency in writing and understanding Kubernetes resource definitions in YAML format.
3. kubectl Commands: Ability to use kubectl apply -f to create resources from a file, and familiarity with terminal text editors like vi or nano.
4. Kubernetes API Validation: Awareness that Kubernetes API server validates resource definitions for completeness and correctness.
Topics
Community Discussion
No community discussion yet for this question.