因此,我尝试使用以下教程使用 OpenFaaS 的 ingress-operator 创建一个更像 REST 的 api 路径。我验证了 ingress-operator 正在运行,使用kubectl get deploy/ingress-operator -n openfaas -o wide
which shows one available。
但是,它似乎没有正确更改函数的路径。我目前已经部署了基本的node14函数,访问http://gw.example.kube/function/test-fn可以正常调用。我还应用了以下 FunctionIngress:
apiVersion: openfaas.com/v1alpha2
kind: FunctionIngress
metadata:
name: test-fn
namespace: openfaas
spec:
domain: example.kube
function: test-fn
ingressType: nginx
path: /api/v1/test/(.*)
但是访问http://example.kube/api/v1/test会导致来自 Nginx 的 404。我尝试(.*)
在重新访问页面时删除将为 OpenFaaS 自己的 404 页面提供服务的那个。两者example.kube
和gw.example.kube
都已在主机文件中设置。重新启动集群也没有解决问题。
附加信息:
$ kubectl get ingress -n openfaas
NAME CLASS HOSTS ADDRESS PORTS AGE
openfaas-ingress <none> gw.example.kube localhost 80 4h9m
test-fn <none> example.kube localhost 80 34m
$ kubectl describe ingress test-fn -n openfaas
Name: test-fn
Namespace: openfaas
Address: localhost
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
example.kube
/api/v1/test/(.*) gateway:8080 (10.1.0.184:8080)
Annotations: com.openfaas.spec:
{"metadata":{"name":"test-fn","namespace":"openfaas","uid":"db7c752f-f08a-403e-9ed1-ad65d616482a","resourceVersion":"14465","gen...
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /function/test-fn/$1
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal AddedOrUpdated 3s (x4 over 43m) nginx-ingress-controller Configuration for openfaas/test-fn was added or updated