Deploying a Flogo App in Knative

You can create and deploy a Flogoapp as a Knative service. For information on Knative, see the Knative documentation.

Flogoapp running inside a Docker container is called by a Knative service. For the app to be called by the Knative service, the app must be exposed over an HTTP port. In this section, a REST Trigger is used to expose the app over an HTTP port.

Before You BeginMake sure you meet the following requirements: 
Note: This section uses a Knative on Kind setup to explain the procedure. However, you can also set it up on minikube and Docker Desktop. For more information, see Setup Knative on Minikube and Setup Knative on Docker Desktop.
    Procedure
  1. Configure a sample Flogo app with a REST Trigger exposed with a port. You can use the default REST Trigger port, 9999.
    Important:
    • Only apps with HTTP endpoints can be deployed as a Knative service. Hence, a REST Trigger is used in this procedure.
    • An app with multiple endpoints on different ports cannot be deployed as a Knative service.

  2. Build the Flogo app for Linux/amd64 platform and save the binary file locally. For more information on building the app binary, see Building the App.
  3. Give executable permissions to the app binary
    chmod a+x <app_executable>
  4. Build a Docker image for the Flogo app and tag it: 
  5. docker build --file Dockerfile -t dev.local/flogoknative:1.0.0 .
  6. Note: Make sure you tag the image in the following format:
    dev.local/<image name>:<tag>
    Instead of the latest tag, use a tag such as 1.0.0.
  7. For more information on building the Docker image, see Build the App Docker Image.

    Here is the sample Dockerfile used in the above command:

    FROM alpine:3.8
    RUN apk add --no-cache ca-certificates
    WORKDIR /app
    ADD <app_executable> /app/flogoapp
    RUN chmod a+x /app/flogoapp
    ENTRYPOINT ["/app/flogoapp"]

    The Docker image is built:

  8. Confirm that the Docker image is built successfully:
    docker images | grep knative
  9. The details of the flogoknative image are displayed:

  10. To test the Docker image: 
    docker run -it -p 9999:9999 dev.local/flogoknative:1.0.0

    The Flogo runtime logs should be displayed as follows: 

  11. Load the Docker image into the default knative cluster: 

    kind load docker-image dev.local/flogoknative:1.0.0 --name knative

    The Flogo Docker image is loaded inside the knative cluster and is used by Knative to create the service.

  12. Create the Knative service: 

    kn service create helloflogo --image dev.local/flogoknative:1.0.0 --port 9999 --revision-name=<any revision name>

    Note: The port should be same as what the Flogo is listening to. In this case, 9999.

    A service is created and an URL is generated. You should see messages similar to the following:

    The networking layer, routes, ingress, and load balancer are configured for the Knative service.

    To see a list of services, execute the following command: 

    kn service list 

    NOTE: If you notice errors during any of these steps, the service is not created successfully. For tips on troubleshooting, see Troubleshooting Tips.

  13. Append the REST Trigger endpoint path (specified in step 1) to the generated service URL and hit the endpoint using a browser or curl. For curl, the format of the command is curl <URL returned in previous step>/hello/knative.
    You should see the Flogo return message as the response: