Giới thiệu
Trong bài này ta tìm hiểu về Gateway API. Một open-source của Kubernetes SIG-NETWORK.
Mục lục
- Cài đặt
- Triển khai ứng dụng đơn giản
- Kết luận
Có rất nhiều công cụ Gateway API trong thị trường. Để thống nhất tiêu chuẩn định nghĩa Gateway thì Kubernetes SIG-NETWORK đã phát triển Kubernetes Gateway API. Bao gồm các resource như: GatewayClass, Gateway, HTTPRoute, TCPRoute.
Với GatewayClass là thằng Gateway Controller đóng vai trò tạo Gateway trên hạ tầng tương ứng. Ví dụ như Cilium, Kong, Istio, …. Trong bài này ta sẽ dùng minikube để dựng Cluster và cài Kubernetes Gateway API + Cilium Gateway Controller.
Cài đặt
Tạo Cluster:
minikube start --network-plugin=cni --cni=falseCài Cilium CLI (Linux):
Cài Kubernetes Gateway API:
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.0/standard-install.yamlCài Cilium:
helm install cilium cilium/cilium --version 1.14.4 \
--namespace kube-system \
--set kubeProxyReplacement=true \
--set gatewayAPI.enabled=trueĐể bật Cilium Gateway Controller ta thêm thuộc tính gatewayAPI.enabled=true. Để kiểm tra cài thành công ta chạy câu lệnh:
cilium status --waitTriển khai ứng dụng đơn giản
Cài ứng dụng demo:
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.11/samples/bookinfo/platform/kube/bookinfo.yamlỨng dụng ta gồm có hai service chính là Product và Details. Để truy cập Product Service ta gọi vào đường dẫn / và truy cập vào Detail Service với đường dẫn /details.
kubectl get poddetails-v1-5498c86cf5-kjzkj 1/1 Running 0 2m39s
productpage-v1-65b75f6885-ff59g 1/1 Running 0 2m39s
ratings-v1-b477cf6cf-kv7bh 1/1 Running 0 2m39s
reviews-v1-79d546878f-r5bjz 1/1 Running 0 2m39s
reviews-v2-548c57f459-pld2f 1/1 Running 0 2m39s
reviews-v3-6dd79655b9-nhrnh 1/1 Running 0 2m39sTa sẽ tạo Gateway API để định hướng request tới từng Service. Tạo một tệp tin tên là gw.yaml:
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: demo-gateway
spec:
gatewayClassName: cilium
listeners:
- protocol: HTTP
port: 80
name: web-gw
allowedRoutes:
namespaces:
from: SameThuộc tính gatewayClassName ta chọn Cilium Gateway Controller. Chạy câu lệnh apply:
kubectl apply -f gw.yamlSau khi tạo xong để kiểm tra ta làm như sau:
kubectl get gatewayNAME CLASS ADDRESS READY AGE
demo-gateway cilium 10.100.26.37 True 2hTiếp theo để điều hướng request tới ứng dụng ta tạo HTTPRoute, tạo tệp tin tên là gw-route.yaml:
kubectl apply -f gw-route.yamlTiếp theo ta gọi vào Gateway để kiểm tra kết quả, lấy địa chỉ IP của Gateway:
GATEWAY=$(kubectl get gateway my-gateway -o jsonpath='{.status.addresses[0].value}')Kiểm tra Details Service:
curl --fail -s http://"$GATEWAY"/details/1 | jq{
"id": 1,
"author": "William Shakespeare",
"year": 1595,
"type": "paperback",
"pages": 200,
"publisher": "PublisherA",
"language": "English",
"ISBN-10": "1234567890",
"ISBN-13": "123-1234567890"
}Kiểm tra Product Service:
curl -v http://"$GATEWAY"\?great\=exampleKết luận
Vậy là ta đã tìm hiểu xong về cách cài đặt Kubernetes Gateway API + Cilium đơn giản. Bài tiếp theo ta tìm hiểu cách triển khai Kubernetes Gateway với Cilium lên trên EKS.
First AI Journey for DevOps:
- PromptOps: From YAML to AI
- The DevOps AI Advantage
- The AIOps Book