Deploying Flogo Apps to Kubernetes

You can deploy your Flogo apps to a Kubernetes Cluster running locally on bare metal servers, on VMs in hybrid cloud environments, or on fully managed services provided by various cloud providers such as Amazon EKS, Azure Container Service, or Google Kubernetes Engine. Refer to the Kubernetes documentation for more information. To do so, you must create a docker image locally for your app, then push the image to a container registry. When you apply the appropriate app deployment configuration to the Kubernetes cluster, one or more docker containers get created from the docker image that is encapsulated in one or more Kubernetes pods based on the deployment configuration.

Before you begin You must have:
  • The Kubernetes cluster running on your choice of environment
  • Docker 1.18.x or greater installed on your machine
  • kubectl installed on your machine
    Procedure
  1. Build a docker image for your app. You can use one of the following ways to build a docker image:
    Using the UI:
    1. Build a docker image using the Flogo Enterprise UI. For details, see Building the App.
    2. Tag the generated docker image from the command line:
      docker tag <image-id> <app-name>:<version>
      the app tag must be in the format, <app-name>:<app-version>.
    From a Linux binary:
    1. Build a Linux binary using the Linux/amd64 option. For details, see Building the App.
    2. Provide run permission to the app binary: chmod +x <app-binary>
    3. Create a docker file. For example:
      FROM <OS-version>  # for example, FROM alpine:3.7
      WORKDIR /app
      ADD <app-binary> <path-to-app-in-docker-container> # for example, ADD flogo-rest-linux_amd64 /app/flogo-rest
      CMD ["/app/flogo-rest"]
    4. Build the docker image using the docker file. Run the following command:
      docker build -t <app-tag> -f <path-to-Dockerfile> .
      the app tag must be in the format <app-name>:<app-version>
    From the CLI:
    1. Export your app as a JSON file (for example, flogo-rest.json) by clicking Export app on the flow details page.
    2. Build a Linux binary for the app from the CLI. Open a command prompt and change directory to <FLOGO_HOME>/<version>/bin and run:
      builder-<platform>_<arch> build -p linux/amd64 -f <path-to-the-.json-file>

      This generates a linux app binary.

    3. Provide run permission to the app binary:
      chmod +x <app-binary>
    4. Create a docker file. For example:
      FROM <OS-version>  # for example, FROM alpine:3.7
      WORKDIR /app
      ADD <app-binary> <path-to-app-in-docker-container> # for example, ADD flogo-rest-linux_amd64 /app/flogo-rest
      CMD ["/app/flogo-rest"]
    5. Build the docker image using the docker file. Run the following command:
      docker build -t <app-tag> -f <path-to-Dockerfile> .
      The app tag must be in the format <app-name>:<app-version>
  2. Run the docker image locally to verify that all looks good:
    docker run -it -p 9999:9999 <app-tag>
  3. Authenticate docker with the container registry where you want to push the docker image.
  4. Tag the docker image by running the following command:
    docker tag <app-tag> <CONTAINER_REGISTRY_URI>/<app-tag>
    the app tag must be in the format, <app-name>:<app-version>
  5. Push the local docker image to the container registry by running the following command:
    docker push <CONTAINER_REGISTRY_URI>/<app-tag>

    Note: Refer to the documentation for your container registry for the exact commands to authenticate docker, tag docker image, and push it to the registry.

  6. To deploy your app on Kubernetes, run your app by creating a Kubernetes deployment object. Follow these steps to do so:
    1. Create a YAML file. For example, the YAML file below describes a deployment that runs the gcr.io/<GCP_PROJECT_ID>/<docker-image-name>:<tag> docker image on the Google Cloud.
      apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
      kind: Deployment
      metadata:
        name: flogo-app-deployment
      spec:
        selector:
          matchLabels:
            app: flogo-app
        replicas: 2 # tells deployment to run 2 pods matching the template
        template:
          metadata:
            labels:
              app: flogo-app
          spec:
            containers:
            - name: flogo-app
              image: gcr.io/<GCP_PROJECT_ID>/<docker-image-name>:<tag>
              ports:
            - containerPort: 9999
    2. Create a Kubernetes deployment by running the following command:
      kubectl apply -f deployment.yaml