使用 Istio 和 Apisix 实现全链路灰度测试(二)
部署 bookinfo 应用
# 因为 bookinfo 应用官方默认部署在 default 命名空间,所以需要提前开启自动注入 Sidecar.
kubectl label namespace default istio-injection=enabled
mkdir -p /data/yaml/default/
# 下载应用
cd /tmp
wget https://codeload.github.com/istio/istio/zip/refs/heads/release-1.20
mv release-1.20 release-1.20.zip
unzip release-1.20.zip
cd /tmp/istio-release-1.20/samples
cp -r bookinfo /data/yaml/default/
cd /data/yaml/default/bookinfo
# 部署应用
kubectl apply -f platform/kube/bookinfo.yaml
# 确认所有的服务和 Pod 都已经正确的定义和启动
kubectl get services
kubectl get pods
kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"
测试正常

使用 Apisix 作为入口网关
# istio-system 命名空间,所以需要提前开启自动注入 Sidecar.
kubectl label namespace istio-system istio-injection=enabled
# 部署 Apisix 可以参考 https://www.cnblogs.com/klvchen/articles/17864795.html
mkdir -p /data/yaml/default/ingress-apisix
cd /data/yaml/default/ingress-apisix
cat >> apisix-ar.yaml << EOF
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
namespace: default
name: productpage
spec:
http:
- backends:
- serviceName: productpage # 制定 bookinfo 的入口 service
servicePort: 9080 # 端口
match:
hosts:
- test.klvchen.com # 测试使用的域名
paths:
- /*
name: route-default
EOF
kubectl apply -f apisix-ar.yaml
检查

浏览器访问 http://test.klvchen.com/productpage

已经成功通过 Apisix 网关访问到 bookinfo 应用
参考
https://istio.io/latest/zh/docs/examples/bookinfo/
https://istio.io/latest/zh/docs/tasks/traffic-management/request-routing/
https://apisix.apache.org/zh/blog/2021/12/17/exposure-istio-with-apisix-ingress/

浙公网安备 33010602011771号