ข้ามไปเนื้อหาหลัก
คอนเทนเนอร์· ~15 นาที

Ingress — ประตูหน้าเดียวสู่หลาย Service

route HTTP ตาม host/path เข้าหลาย service ด้วย LB ตัวเดียว

เปรียบเทียบให้เห็นภาพ

Ingress เหมือนพนักงานต้อนรับหน้าตึก ที่ดูว่าแขกมาหาแผนกไหน (ดูจากชื่อโดเมน/path) แล้วชี้ทางไปห้องที่ถูก · แทนที่จะจ้าง LoadBalancer (ซึ่งมีค่าใช้จ่าย) หนึ่งตัวต่อ service เราใช้ Ingress ตัวเดียวคุมหลาย service

ปัญหาของ Service แบบ LoadBalancer คือ ถ้ามี 10 service ก็ต้องมี 10 LB (แพงและจัดการยาก) · Ingress ให้เราใช้จุดเข้า HTTP/HTTPS จุดเดียว แล้วกำหนดกฎ routing ตาม host หรือ path

Ingress ตัวเดียวแยก traffic ตาม path ไปหลาย Service

ผู้ใช้ (HTTPS)
Ingressexample.com
/app →
Service: web
Podsfrontend
/api →
Service: api
Podsbackend
Ingress ตัวเดียวหน้าสุด แยก traffic ตาม host/path ไปยังหลาย Service ด้านหลัง
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: main
spec:
  rules:
    - host: example.com
      http:
        paths:
          - path: /app
            pathType: Prefix
            backend:
              service: { name: web, port: { number: 80 } }
          - path: /api
            pathType: Prefix
            backend:
              service: { name: api, port: { number: 80 } }
ingress.yaml — แยก path /app และ /api

สรุป Key Takeaways

  • Ingress = กฎ routing HTTP/HTTPS ตาม host/path เข้าหลาย Service ด้วยจุดเข้าเดียว
  • ประหยัดกว่าการมี LoadBalancer หนึ่งตัวต่อ service
  • ต้องมี Ingress Controller (NGINX/ALB) ทำงานตามกฎจริง
  • มักทำ TLS termination ที่ Ingress
อ่านจบแล้วอย่าลืมทำเครื่องหมาย