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:
- 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: 2
name: web-route
namespace: cka7395
resourceVersion: “1644”
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: /
- group: “”
- backendRefs:
- group: “”
kind: Service
name: api-service
port: 8080
weight: 1
matches: - path:
type: PathPrefix
value: /api
status:
parents:
- group: “”
- conditions:
- lastTransitionTime: “2025-05-01T05:31:05Z”
message: The route is accepted
observedGeneration: 2
reason: Accepted
status: “True”
type: Accepted - lastTransitionTime: “2025-05-01T05:31:05Z”
message: All references are resolved
observedGeneration: 2
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: “”
- lastTransitionTime: “2025-05-01T05:31:05Z”
- group: gateway.networking.k8s.io