Yeh guide hai Kubernetes Gateway API ke baare mein, jo ek modern aur flexible tareeka hai ingress aur traffic routing manage karne ka Kubernetes mein. Hum NGINX Gateway Controller use karenge demo ke liye, lekin concepts aur APIs universal hain, aur kisi bhi Gateway API-compatible controller ke saath kaam karte hain.
Gateway API custom resources define karta hai, lekin unhe implement karne ke liye ek controller chahiye. Hum NGINX Gateway Controller use kar rahe hain jo saare standard Gateway API resources support karta hai.
method.service: gRPC service ka naam (e.g., my.grpc.Service).
method.method: Specific gRPC method (e.g., GetData).
Use: Microservices ke beech communication ke liye.
Conclusion: Kyun Use Karein? π―
Kubernetes Gateway API ek powerful aur structured tareeka hai traffic manage karne ka. Features jaise header rewrites, traffic splits, aur protocol flexibility make it super expressive. Start with HTTP basics, then move to advanced protocols like TLS, TCP, ya gRPC. Yeh ensure karta hai smooth, secure, aur scalable ingress strategy for your Kubernetes clusters.
Ab try karo aur apne cluster ko next level par le jao! π
Kubernetes Gateway API
Yeh guide hai Kubernetes Gateway API ke baare mein, jo ek modern aur flexible tareeka hai ingress aur traffic routing manage karne ka Kubernetes mein. Hum NGINX Gateway Controller use karenge demo ke liye, lekin concepts aur APIs universal hain, aur kisi bhi Gateway API-compatible controller ke saath kaam karte hain.
π Official Docs: gateway-api.sigs.k8s.io
1. Gateway API Install Karna with NGINX π οΈ
Gateway API custom resources define karta hai, lekin unhe implement karne ke liye ek controller chahiye. Hum NGINX Gateway Controller use kar rahe hain jo saare standard Gateway API resources support karta hai.
Commands to install NGINX Gateway Controller:
Kya hota hai yeh?
π Reference: NGINX Gateway Fabric Docs
2. GatewayClass: Blueprint for Gateways ποΈ
GatewayClass ek template hai jo batata hai kaunsa controller Gateways manage karega. Isko aise samjho:
Example:
Samjho:
controllerName
: Yeh batata hai kaunsa controller (jaisenginx.org/gateway-controller
) is GatewayClass ke Gateways ko handle karega.π Docs: GatewayClass Reference
3. HTTP Gateway aur Listener Setup π‘
Gateway resource define karta hai ki traffic kaise cluster mein aayega β protocols, ports, aur routing rules ke saath.
Example for HTTP Gateway:
Explanation:
gatewayClassName
: Yehnginx
GatewayClass ko point karta hai.listeners
: Batata hai Gateway kaise traffic sunega.name
: Listener ka unique naam.protocol
: HTTP traffic ke liye set hai.port
: 80 par HTTP traffic sunega.allowedRoutes
:from: All
matlab saare namespaces se routes allow hain.Kaam: Yeh HTTP traffic ko port 80 par handle karta hai aur backend services ko forward karta hai.
4. HTTP Routing: Traffic Ko Direct Karna π€οΈ
HTTPRoute batata hai ki HTTP traffic kaise specific services tak jayega. Yeh Gateway ke saath milke kaam karta hai.
Example:
Kya hai yeh?
parentRefs
: Is route konginx-gateway
se link karta hai.rules
: Traffic kaise route hoga, yeh define karta hai.matches
: Requests ko match karta hai, jaise/app
path prefix.backendRefs
: Traffic komy-app
service ke port 80 par bhejta hai.Kaam:
/app
se start hone wale requestsmy-app
service tak jayenge.π Docs: HTTP Routing Guide
5. HTTP Redirects aur Rewrites π
Redirects aur Rewrites se requests ko modify kar sakte ho before they reach backend.
HTTP to HTTPS Redirect
Force HTTP traffic to HTTPS for security.
Kaise kaam karta hai?
filters
: Request ko process karta hai.RequestRedirect
: HTTP ko HTTPS mein redirect karta hai.π Docs: Redirects Guide
Path Rewrite
Request ka path change karo before forwarding.
Kya hota hai?
/old
path ko/new
se replace karta hai.my-app
service ke port 80 par jata hai.π Docs: Rewrite Guide
6. HTTP Header Modification π·οΈ
Headers ko add, set, ya remove kar sakte ho requests ya responses mein.
Example:
Kaise kaam karta hai?
RequestHeaderModifier
: Ek custom headerx-env: staging
add karta hai.my-app
service tak jata hai.Use: Environment-specific metadata add karne ke liye useful hai.
π Docs: Header Guide
7. HTTP Traffic Splitting: Divide and Rule π¦
Traffic ko multiple backend services mein split kar sakte ho, jaise canary deployments ya A/B testing ke liye.
Example:
Kya hota hai?
v1-service
ko jata hai.v2-service
ko jata hai.Use: New features test karne ya rollout ke liye perfect hai.
π Docs: Traffic Splitting Guide
8. HTTP Request Mirroring πͺ
Requests ki copy ek secondary service ko bhej sakte ho for testing ya analysis, bina primary service ko affect kiye.
Example:
Kaise kaam karta hai?
my-app
ko jata hai.mirror-service
ko bheji jati hai.Use: New services test karne ya traffic analyze karne ke liye useful.
π Docs: Request Mirroring Guide
9. TLS Configuration: Secure Karo π
TLS se traffic encrypt hota hai, ensuring secure communication. Gateway level par TLS terminate kar sakte ho using a Kubernetes Secret.
Example for TLS Termination:
Explanation:
protocol
: HTTPS traffic handle karta hai.tls.mode: Terminate
: Gateway traffic decrypt karta hai.certificateRefs
:tls-secret
Secret mein TLS certificate aur key stored hote hain.allowedRoutes
: Saare namespaces se routes allow hain.Kaam: Secure communication ke liye, backend services ko unencrypted traffic milta hai.
π Docs: TLS Guide
10. TCP, UDP, aur Other Protocols π
Gateway API sirf HTTP nahi, TCP, UDP, aur gRPC jaise protocols bhi support karta hai, making it versatile for databases, DNS, microservices, etc.
TCP Example (Databases ke liye)
Kya hai?
protocol
: TCP traffic ke liye.port
: 3306 (MySQL ke liye common).UDP Example (DNS ya Streaming ke liye)
Kya hai?
protocol
: UDP traffic ke liye.port
: 53 (DNS ke liye common).gRPC Example (Microservices ke liye)
Kya hai?
method.service
: gRPC service ka naam (e.g.,my.grpc.Service
).method.method
: Specific gRPC method (e.g.,GetData
).Conclusion: Kyun Use Karein? π―
Kubernetes Gateway API ek powerful aur structured tareeka hai traffic manage karne ka. Features jaise header rewrites, traffic splits, aur protocol flexibility make it super expressive. Start with HTTP basics, then move to advanced protocols like TLS, TCP, ya gRPC. Yeh ensure karta hai smooth, secure, aur scalable ingress strategy for your Kubernetes clusters.
Ab try karo aur apne cluster ko next level par le jao! π