1 | initial version |
To configure a Kubernetes ingress to prioritize the local availability zone, you need to set the appropriate node selector labels for your nodes and your ingress resource. Here are the steps:
kubectl label nodes node-a zone=az-a
kubectl label nodes node-b zone=az-b
kubectl label nodes node-c zone=az-c
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
nodeSelector:
zone: az-a # pod will be scheduled on a node in az-a
containers:
- name: my-container
image: nginx
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/affinity: "cookie"
spec:
nodeSelector:
zone: az-a # traffic will be routed to a node in az-a
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: my-service
servicePort: 80
With these configurations, Kubernetes will route traffic to the local availability zone first, ensuring better performance and reduced latency for your users.