Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

title linkTitle weight type
Hello World - Eclipse Vert.x
Eclipse Vert.x

Learn how to deploy a simple web app that is written in Java and uses Eclipse Vert.x. This samples uses Docker to build locally. The app reads in a TARGET env variable and then prints "Hello World: ${TARGET}!". If a value for TARGET is not specified, the "NOT SPECIFIED" default value is used.

Use this sample to walk you through the steps of creating and modifying the sample app, building and pushing your container image to a registry, and then deploying your app to your Knative cluster.

Before you begin

You must meet the following requirements to complete this sample:

Tip: You can clone the Knative/docs repo and then modify the source files. Alternatively, learn more by manually creating the files yourself.

Creating and configuring the sample code

To create and configure the source files in the root of your working directory:

  1. Create the pom.xml file:

    <project xmlns=""
  2. Create the file in the src/main/java/com/example/helloworld directory. The [ROOT]/src/main/java/com/example/helloworld/ file creates a basic web server that listens on port 8080.

     package com.example.helloworld;
     import io.reactivex.Flowable;
     import io.vertx.reactivex.core.AbstractVerticle;
     import io.vertx.reactivex.core.http.HttpServer;
     import io.vertx.reactivex.core.http.HttpServerRequest;
     public class HelloWorld extends AbstractVerticle {
         public void start() {
             final HttpServer server = vertx.createHttpServer();
             final Flowable<HttpServerRequest> requestFlowable = server.requestStream().toFlowable();
             requestFlowable.subscribe(httpServerRequest -> {
                 String target = System.getenv("TARGET");
                 if (target == null) {
                     target = "NOT SPECIFIED";
                         .putHeader("content-type", "text/plain")
                         .setStatusCode(200) // OK
                         .end("Hello World: " + target);
  3. Create the Dockerfile file:

    # Use fabric8's s2i Builder image.
    FROM fabric8/s2i-java:2.0
    # Copy the JAR file to the deployment directory.
    ENV JAVA_APP_DIR=/deployments
    COPY target/helloworld-1.0.0-SNAPSHOT.jar /deployments/
  4. Create the service.yaml file. You must specify your Docker Hub username in {username}. You can also configure the TARGET, for example you can modify the Eclipse Vert.x Sample v1 value.

    kind: Service
      name: helloworld-vertx
      namespace: default
            - image:{username}/helloworld-vertx
                - name: TARGET
                  value: "Eclipse Vert.x Sample v1"

Building and deploying the sample

To build a container image, push your image to the registry, and then deploy your sample app to your cluster:

  1. Use Docker to build your container image and then push that image to your Docker Hub registry. You must replace the {username} variables in the following commands with your Docker Hub username.

    # Build the container on your local machine
    docker build -t {username}/helloworld-vertx .
    # Push the container to docker registry
    docker push {username}/helloworld-vertx
  2. Now that your container image is in the registry, you can deploy it to your Knative cluster by running the kubectl apply command:

    kubectl apply --filename service.yaml

    Result: A service name helloworld-vertx is created in your cluster along with the following resources:

    • A new immutable revision for the version of the app that you just deployed.
    • The following networking resources are created for your app:
      • route
      • ingress
      • service
      • load balancer
    • Auto scaling is enable to allow your pods to scale up to meet traffic, and also back down to zero when there is no traffic.

Testing the sample app

To verify that your sample app has been successfully deployed:

  1. View your the ingress IP address of your service by running the following kubectl get command. Note that it may take sometime for the new service to get asssigned an external IP address, especially if your cluster was newly created.

    # In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`.
    # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x.
    # Use `istio-ingressgateway` instead, since `knative-ingressgateway`
    # will be removed in Knative v0.4.
    if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
    kubectl get svc $INGRESSGATEWAY --namespace istio-system

    Example result:

    NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                      AGE
    xxxxxxx-ingressgateway   LoadBalancer   80:32380/TCP,443:32390/TCP,32400:32400/TCP   2d
  2. Retrieve the URL for your service, by running the following kubectl get command:

    kubectl get helloworld-vertx,URL:.status.url

    Example result:

    NAME                URL
  3. Run the following curl command to test your deployed sample app. You must replace the {IP_ADDRESS} variable the URL that your retrieve in the previous step.

    curl -H "Host:" http://{IP_ADDRESS}

    Example result:

     Hello World: Eclipse Vert.x Sample v1

Congtratualations on deploying your sample Java app to Knative!

Removing the sample app deployment

To remove the sample app from your cluster, run the following kubectl delete command:

kubectl delete --filename service.yaml
You can’t perform that action at this time.