ตั้งค่า Service และ Route ของ Kong Gateway ในโหมด DB-less
Service กำหนดการเชื่อมต่อ upstream ส่วน Route ส่งคำขอที่ตรงเงื่อนไขไปยัง Service โหมด DB-less ใช้ไฟล์ YAML/JSON แบบ declarative ไฟล์เดียวระบุสถานะ entity ทั้งหมด และการโหลดจะแทนที่ทั้งชุด ตัวอย่างใช้ HTTP path route และ format v3 เอกสารปัจจุบันระบุว่าตั้งแต่ v3.14 Route รับเฉพาะ HTTPS โดยปริยาย จึงระบุทั้ง HTTP และ HTTPS ชัดเจน ไม่ครอบคลุม database mode, Kubernetes Ingress Controller, Konnect หรือ authentication plugin
Service กำหนดการเชื่อมต่อ upstream ส่วน Route ส่งคำขอที่ตรงเงื่อนไขไปยัง Service โหมด DB-less ใช้ไฟล์ YAML/JSON แบบ declarative ไฟล์เดียวระบุสถานะ entity ทั้งหมด และการโหลดจะแทนที่ทั้งชุด ตัวอย่างใช้ HTTP path route และ format v3 เอกสารปัจจุบันระบุว่าตั้งแต่ v3.14 Route รับเฉพาะ HTTPS โดยปริยาย จึงระบุทั้ง HTTP และ HTTPS ชัดเจน ไม่ครอบคลุม database mode, Kubernetes Ingress Controller, Konnect หรือ authentication plugin
Entity DB-less อยู่ในหน่วยความจำ node ไม่มีการประสานผ่านฐานข้อมูลกลาง แต่ละ node จึงต้องได้ config ที่ต้องการ และ entity ต้องพอดีกับ cache ส่วน plugin รองรับแตกต่างกัน ตัวอย่างจับคู่ /orders กับ orders_api; strip_path=true ตัด prefix ทำให้ /orders/42 ไปถึง upstream เป็น /42 เลือก upstream ที่ Gateway เข้าถึงได้
ตั้งค่าและตรวจสอบ
_format_version: "3.0"
services:
- name: orders_api
url: http://orders.internal.example:8080
routes:
- name: orders_path
service:
name: orders_api
paths:
- /orders
protocols:
- http
- https
strip_path: truekong config parse kong.yml ตรวจเฉพาะ syntax ไม่ได้ load ไฟล์หรือยืนยัน DNS การเชื่อมต่อหรือ runtime ตั้ง database=off และ declarative_config เป็นไฟล์เต็ม หรือใช้ KONG_DATABASE กับ KONG_DECLARATIVE_CONFIG ตรวจทั้งไฟล์ เก็บ config เต็มชุดล่าสุดที่ดี และใช้กับทุก node ตรวจคำขอผ่าน proxy listener จริงและดู log จำกัด Admin API และอย่าเปิดพอร์ตจัดการสู่สาธารณะ
ข้อจำกัด
ตัวอย่างเอกสารนี้ไม่ได้รัน การระบุ HTTPS ไม่ได้ตั้งค่า TLS หรือ certificate ตรวจสอบกับเวอร์ชันติดตั้ง
[DB-less](https://developer.konghq.com/gateway/db-less-mode/)
[Gateway Services](https://developer.konghq.com/gateway/entities/service/)
[Routes](https://developer.konghq.com/gateway/entities/route/)
[CLI](https://developer.konghq.com/gateway/cli/reference/)
[การตั้งค่า](https://developer.konghq.com/gateway/manage-kong-conf/)