Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose UDP port using traits and make it accessible outside of the pod #2693

Open
haifzhan opened this issue Oct 13, 2021 · 2 comments
Open
Labels

Comments

@haifzhan
Copy link

haifzhan commented Oct 13, 2021

I have started a Java integration which is listening on port 8843. The integration works properly and it can receive syslog events in the container of the pod. I am trying to expose the port and makes it accessible outside of the pod, what is the right way to expose it?

I have tried added traits but don't have any luck, I have asked the question on StackOverflow can some shed some light on this?

// Split commands into multiple lines for easy read
$ kamel run \
--trait container.enabled=true  \
--trait container.expose=true \
--trait container.port=8443 \
--trait service.node-port=true \
SyslogBasic.java --dev
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.spi.DataFormat;

import org.apache.camel.component.syslog.SyslogDataFormat;

public class SysLogBasic extends RouteBuilder {

 @Override
  public void configure() throws Exception {
    DataFormat syslogDataFormat = new SyslogDataFormat();
    String HOST = "0.0.0.0";
    int PORT = 8443;
    from("netty:udp://" + HOST + ":" + PORT + "?sync=false").unmarshal(syslogDataFormat).process(new Processor() {
      public void process(Exchange exchange) {
        // implemented business logic
      }
    }).to("log:info");
  }
}
@astefanutti astefanutti changed the title Expose port using traits and make it accessible outside of the pod Expose UDP port using traits and make it accessible outside of the pod Oct 14, 2021
@astefanutti
Copy link
Member

astefanutti commented Oct 14, 2021

As of Camel K version 1.6, the auto-configuration of the container port is only available for the HTTP protocol, as reported by the condition:

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

You can achieve it manually, by exposing the container port using the kamel run --pod-template option, with the following template.yaml file:

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

And creating the Service manually, e.g.:

$ 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: 8443
      targetPort: 8443
EOF

Then you can run the integration with:

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

And send a Syslog trace using Netcat, e.g.:

$ 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 8443"

Finally you can check in the integration logs the trace has been processed, e.g.:

$ 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]

I've re-titled the issue to make it specific to UDP. We'll work on it ASAP.

@astefanutti astefanutti added the kind/feature New feature or request label Oct 14, 2021
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale due to 90 days of inactivity.
It will be closed if no further activity occurs within 15 days.
If you think that’s incorrect or the issue should never stale, please simply write any comment.
Thanks for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants