CKA ultimate series Mock exam2: Q14

Hi Team,

My question is related to weight value for second api-service that we added. How much should the weight value for the api-service ?

Also, how to check the following Is the traffic reaching the deployment?. Kindly assist. Thanks !

Solve this question on: ssh cluster3-controlplane


Extend the web-route on cka7395 to direct traffic with the path prefix /api to a service named api-service on port 8080, while all other traffic continues to route to web-service.


Is the web-route configured to direct traffic to the api-service?

Is the traffic reaching the deployment?

Answer:

Actual Yaml of the route

cluster3-controlplane ~ âś– k get httproutes.gateway.networking.k8s.io -n cka7395 -o yaml 
apiVersion: v1
items:
- apiVersion: gateway.networking.k8s.io/v1
  kind: HTTPRoute
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"gateway.networking.k8s.io/v1","kind":"HTTPRoute","metadata":{"annotations":{},"name":"web-route","namespace":"cka7395"},"spec":{"parentRefs":[{"name":"nginx-gateway","namespace":"nginx-gateway"}],"rules":[{"backendRefs":[{"name":"web-service","port":80}],"matches":[{"path":{"type":"PathPrefix","value":"/"}}]}]}}
    creationTimestamp: "2025-05-01T05:26:15Z"
    generation: 1
    name: web-route
    namespace: cka7395
    resourceVersion: "1392"
    uid: cc6bed1d-63ec-442f-891b-dc2cb6cbe481
  spec:
    parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: nginx-gateway
      namespace: nginx-gateway
    rules:
    - backendRefs:
      - group: ""
        kind: Service
        name: web-service
        port: 80
        weight: 1
      matches:
      - path:
          type: PathPrefix
          value: /
  status:
    parents:
    - conditions:
      - lastTransitionTime: "2025-05-01T05:26:15Z"
        message: The route is accepted
        observedGeneration: 1
        reason: Accepted
        status: "True"
        type: Accepted
      - lastTransitionTime: "2025-05-01T05:26:15Z"
        message: All references are resolved
        observedGeneration: 1
        reason: ResolvedRefs
        status: "True"
        type: ResolvedRefs
      controllerName: gateway.nginx.org/nginx-gateway-controller
      parentRef:
        group: gateway.networking.k8s.io
        kind: Gateway
        name: nginx-gateway
        namespace: nginx-gateway
kind: List
metadata:
  resourceVersion: ""

- Updated the route  yaml with `api-service`

cluster3-controlplane ~ âžś k get httproutes.gateway.networking.k8s.io -n cka7395 -o yaml
apiVersion: v1
items:

Firstly, you didn’t paste your solution in a

code block

so it is illegible.

However, what I can say is this

  1. weight value is irrelevant and can be left out unless you have more than one entry for the same backendRefs. Weighting is for canary deployment of the same service from one version to another so that you can send some of the traffic to the new version of the service and some to the old to check for errors, before fully switching to the new version. This question is not testing that, since you have different services on different backendRefs
  2. How do you test it? You need to curl through the gateway to the service path, so what you need is the gateway’s node port then access it like any other nodeport service
    1. kubectl get svc -n nginx-gateway. Note the nodeport for http (80) access.
    2. kubectl get nodes -o wide. Note the IP address of the node
    3. curl 192.168.129.204:30080/api (the node IP address will be different for you)., See the result
      {"message": "Hello from API"}
      
2 Likes

Hi @Alistair_KodeKloud ,

Thanks for getting back.

If you see the actual yaml that I pasted in the initial response , the service added in the **backend-reference has weight 1**. If we add another service api-service, we need to add weight to that or add it without weight. That’s my question :slight_smile .

 rules:
    - backendRefs:
      - group: ""
        kind: Service
        name: web-service
        port: 80
        weight: 1
      matches:
      - path:
          type: PathPrefix
          value: /

My other question has been unanswered.

Thanks,
Sakshi

I have answered both questions above. Please carefully re-read my reply.

I tell you that you do not need weight and why, and also how to test that the new service works

1 Like

@sakshibag80 thanks for asking this! I solved the question but I guess I didn’t understand the solution in this depth. lol

1 Like