1

我正在尝试设置一个 Knative 事件管道,其中存在一个接受外部 gRPC 请求并将事件触发到代理以进行进一步处理的容器。

在我的玩具示例中,我没有使用 SinkBinding 注入K_SINK环境变量。这是我的配置的相关部分:

apiVersion: v1
kind: Namespace
metadata:
  name: bora-namespace
  labels:
    eventing.knative.dev/injection: enabled

---

apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
  name: my-broker
  namespace: bora-namespace

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ease-pipeline-server
  namespace: bora-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ease-pipeline-server
  template:
    metadata:
      labels:
        app: ease-pipeline-server
    spec:
      containers:
        - name: ease-pipeline-server
          image: docker.io/boramalper/ease-pipeline-server:latest
          imagePullPolicy: Always

---

apiVersion: sources.knative.dev/v1
kind: SinkBinding
metadata:
  name: bind-ease-pipeline-server
  namespace: bora-namespace
spec:
  subject:
    apiVersion: apps/v1
    kind: Deployment
    selector:
      matchLabels:
        app: ease-pipeline-server
  sink:
    ref:
      apiVersion: eventing.knative.dev/v1
      kind: Broker
      name: my-broker

---

kind: Service
apiVersion: v1
metadata:
  name: ease-pipeline-server
  namespace: bora-namespace
spec:
  type: NodePort
  selector:
    app: ease-pipeline-server
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
      nodePort: 30002

由于缺少环境变量,我的容器陷入了无限崩溃循环。

SinkBinding 对象似乎没有问题:

$ kubectl --namespace bora-namespace get sinkbinding
NAME                        SINK                                                                                AGE   READY   REASON
bind-ease-pipeline-server   http://broker-ingress.knative-eventing.svc.cluster.local/bora-namespace/my-broker   22m   True    

系统信息:

$ kn version
Version:      v20210526-local-0c6ef82
Build Date:   2021-05-26 06:34:50
Git Revision: 0c6ef82
Supported APIs:
* Serving
  - serving.knative.dev/v1 (knative-serving v0.23.0)
* Eventing
  - sources.knative.dev/v1 (knative-eventing v0.23.0)
  - eventing.knative.dev/v1 (knative-eventing v0.23.0)

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.6", GitCommit:"8a62859e515889f07e3e3be6a1080413f17cf2c3", GitTreeState:"clean", BuildDate:"2021-04-15T03:28:42Z", GoVersion:"go1.15.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.7", GitCommit:"132a687512d7fb058d0f5890f07d4121b3f0a2e2", GitTreeState:"clean", BuildDate:"2021-05-12T12:32:49Z", GoVersion:"go1.15.12", Compiler:"gc", Platform:"linux/amd64"}

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:    18.04
Codename:   bionic

$ uname -a
Linux REDACTED 4.15.0-137-generic #141-Ubuntu SMP Fri Feb 19 13:46:27 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
4

1 回答 1

3

SinkBinding对象有一个使用标签选择器配置的主题:

subject:
  apiVersion: apps/v1
  kind: Deployment
  selector:
    matchLabels:
      app: ease-pipeline-server

但是,对象上没有设置这样的标签Deployment

metadata:
  name: ease-pipeline-server
  # no labels

这里的解决方案是:

  • 将相应的标签添加到部署的metadata

    metadata:
      name: ease-pipeline-server
      labels:
        app: ease-pipeline-server
    
  • name在部署的(API 文档)上使用主题匹配

    subject:
      apiVersion: apps/v1
      kind: Deployment
      name: ease-pipeline-server
    
于 2021-05-26T10:40:15.980 回答