【问题标题】:Knative Service can't be triggered by Knative Broker & TriggerKnative 服务不能被 Knative Broker & Trigger 触发
【发布时间】:2020-02-16 17:53:26
【问题描述】:

我正在 GKE 中测试 Knative,这是我想做的:

但是,我在“default-broker-filter”的日志中收到以下错误:

caller: "http/transport.go:508"   
error: "Post http://helloworld-python.knative-samples.svc.cluster.local: dial tcp: lookup helloworld-python.knative-samples.svc.cluster.local on 10.0.0.10:53: no such host"   
level: "warn"   
logger: "fallback"   
msg: "got an error from receiver fn" 

我使用this official tutorial通过以下命令安装Knative:

kubectl apply --selector knative.dev/crd-install=true \
--filename https://github.com/knative/serving/releases/download/v0.12.0/serving.yaml \
--filename https://github.com/knative/eventing/releases/download/v0.12.0/eventing.yaml \
--filename https://github.com/knative/serving/releases/download/v0.12.0/monitoring.yaml

kubectl apply --filename https://github.com/knative/serving/releases/download/v0.12.0/serving.yaml \
--filename https://github.com/knative/eventing/releases/download/v0.12.0/eventing.yaml \
--filename https://github.com/knative/serving/releases/download/v0.12.0/monitoring.yaml

这是我用来在 python 中安装触发器和服务 hello world 的 yaml 模板:

# Namespace for sample application with eventing enabled
apiVersion: v1
kind: Namespace
metadata:
  name: knative-samples
  labels:
    knative-eventing-injection: enabled
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-python
  namespace: knative-samples
spec:
  template:
    spec:
      containers:
        - image: gcr.io/knative-samples/helloworld-python
          env:
            - name: TARGET
              value: "Python Sample v1"

---
# Knative Eventing Trigger to trigger the helloworld-go service
apiVersion: eventing.knative.dev/v1alpha1
kind: Trigger
metadata:
  name: my-service-trigger
  namespace: knative-samples
spec:
  broker: default
  filter:
    attributes:
      type: dev.knative.samples.helloworld
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: helloworld-python

然后我创建一个 pod 来执行我的 curl 命令:

kubectl --namespace knative-samples run curl --image=radial/busyboxplus:curl -it

curl -v "default-broker.knative-samples.svc.cluster.local" \
  -X POST \
  -H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
  -H "Ce-specversion: 0.3" \
  -H "Ce-Type: dev.knative.samples.helloworld" \
  -H "Ce-Source: dev.knative.samples/helloworldsource" \
  -H "Content-Type: application/json" \
  -d '{"msg":"Hello World from the curl pod."}'

你能告诉我这是怎么回事,因为我整个周末都没有找到任何线索吗?

谢谢,

【问题讨论】:

  • 您在 GKE 上运行的是哪个版本的 Kubernetes?
  • 这个版本1.14.10-gke.17

标签: google-kubernetes-engine knative knative-serving knative-eventing


【解决方案1】:

您是否启用了集群本地网关?如果不是,那么这可能是它不起作用的原因。详情见以下链接:

https://knative.dev/docs/install/installing-istio/

【讨论】:

    【解决方案2】:

    您的应用程序仅接受 GET 请求,如您在此处所见 - https://github.com/knative/docs/blob/master/docs/serving/samples/hello-world/helloworld-python/app.py

    正如您在 cloudevents 规范中看到的 - https://github.com/cloudevents/spec/blob/master/http-webhook.md#21-delivery-request

    传送请求的 HTTP 方法必须是 POST。

    你必须使用POST方法来触发你的服务。

    如果你想修复它,你有两个简单的选择:

    1. 您可以将服务的镜像更改为event_display (gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/event_display)

    2. 您可以更改应用程序的代码,将L7@app.route('/')更改为@app.route('/', methods=['GET', 'POST'])

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 2020-06-12
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-19
      相关资源
      最近更新 更多