Camel 使用特征暴露UDP端口,并使其可在机架外部访问

yshpjwxd  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(175)

更新:此问题已在Camel K GitHub Issues下回答:https://github.com/apache/camel-k/issues/2693

我有一个Camel K项目,它使用端口4739。现在我只能在登录到Pod容器时将数据发送到端口。
我正在尝试将数据发送到容器之外,有人知道如何配置吗?
已尝试以下命令,但似乎不起作用...

// Split commands into multiple lines for easy read
kamel run 
--trait container.enabled=true  
--trait container.expose=true 
--trait container.port=4739 
--trait service.node-port=true 
SyslogBasic.java --dev

我的理解是容器位于pod内部。首先我们需要将容器端口暴露给pod,然后使用服务将端口暴露给外部,遗憾的是,我还没有找到任何与服务端口相关的命令行。

(base) ➜  ~ kamel describe integration syslog-basic
Name:                syslog-basic
Namespace:           camel-basic
Creation Timestamp:  Fri, 08 Oct 2021 15:31:27 -0600
Phase:               Running
Runtime Version:     1.9.0
Kit:                 camel-basic/kit-c59mu55np3m8mfiq07hg
Image:               10.100.204.194/camel-basic/camel-k-kit-c59mu55np3m8mfiq07hg@sha256:06d02dbdda3a58fa0428b9d7cccab9d0708a0172ebe1a9c37e9c1ad114d46769
Version:             1.6.0
Dependencies:
  camel:log
  camel:netty
  mvn:com.fasterxml.jackson.core:jackson-databind:2.12.5
  mvn:io.quarkus:quarkus-logging-json
  mvn:org.apache.camel.k:camel-k-runtime
  mvn:org.apache.camel.quarkus:camel-quarkus-java-joor-dsl
  mvn:org.apache.camel:camel-syslog:3.11.2
Sources:
  Name              Language  Compression  Ref  Ref Key
  SyslogBasic.java  java      false
Conditions:
  Type                          Status  Reason                        Message
  IntegrationPlatformAvailable  True    IntegrationPlatformAvailable  camel-basic/camel-k
  IntegrationKitAvailable       True    IntegrationKitAvailable       kit-c59mu55np3m8mfiq07hg
  CronJobAvailable              False   CronJobNotAvailableReason     different controller strategy used (deployment)
  DeploymentAvailable           True    DeploymentAvailable           deployment name is syslog-basic
  ServiceAvailable              False   ServiceNotAvailable           no http service required
  ExposureAvailable             False   IngressNotAvailable           no host or service defined
  Ready                         True    ReplicaSetReady
Traits:
  Container:
    Configuration:  map[enabled:true expose:true port:4739]
  Service:
    Configuration:  map[enabled:true nodePort:true]
ws51t4hk

ws51t4hk1#

自Camel K 1.6版起,容器端口的自动配置仅适用于HTTP协议,如以下条件所报告:

Conditions:
  Type              Status  Reason               Message
  ServiceAvailable  False   ServiceNotAvailable  no http service required

您可以使用kamel run --pod-template选项公开容器连接埠,以下列template.yaml档案手动完成此作业:

containers:
  - name: integration
    ports:
      - containerPort: 4739
        protocol: UDP

以及手动创建服务,例如:

$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
  name: service
spec:
  selector:
    camel.apache.org/integration: sys-log-basic
  ports:
    - protocol: UDP
      port: 4739
      targetPort: 4739
EOF

然后,您可以使用以下项运行集成:

$ kamel run SysLogBasic.java --pod-template template.yaml -d camel-syslog

并使用Netcat发送系统日志跟踪,例如:

$ kubectl run -i --rm debug --image=busybox --restart=Never --command -- sh -c "echo '<34>Oct 11 22:14:15 mymachine su: failed on /dev/pts/8' | nc -u -w1 service 4739"

最后,您可以在集成日志中检查已处理的跟踪,例如:

$ kubectl logs -l camel.apache.org/integration=sys-log-basic
2021-10-14 08:09:36,436 INFO  [io.quarkus] (main) camel-k-integration 1.7.0-SNAPSHOT on JVM (powered by Quarkus 2.2.0.Final) started in 1.684s. 
2021-10-14 08:09:36,436 INFO  [io.quarkus] (main) Profile prod activated. 
2021-10-14 08:09:36,437 INFO  [io.quarkus] (main) Installed features: [camel-bean, camel-core, camel-java-joor-dsl, camel-k-core, camel-k-runtime, camel-log, camel-netty, camel-syslog, cdi]
2021-10-14 08:39:06,842 INFO  [info] (Camel (camel-1) thread #1 - NettyConsumerExecutorGroup) Exchange[ExchangePattern: InOnly, BodyType: org.apache.camel.component.syslog.SyslogMessage, Body: <34>Oct 11 22:14:15 mymachine su: failed on /dev/pts/8]

相关问题