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.
- The Kubernetes cluster running on your choice of environment
- Docker 1.18.x or greater installed on your machine
kubectlinstalled on your machine
- Procedure
- Build a docker image for your app. There are three ways to build a docker image for Kubernetes deployment.
Using Flogo Enterprise Web UI:
- Build the docker image from the Flogo Enterprise Web UI. See Building the App section for details.
- 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:- From the
Flogo Enterprise Web UI, build a Linux binary using the
Linux/amd64option. See Building the App section for details. - Provide execute permission to the app binary:
chmod +x <app-binary> - 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"]
- 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:- Export your app as a JSON file (for example,
flogo-rest.json) by clicking the Export app button on the flow details page. - Build a Linux binary for the app from the CLI. Open a command prompt and change directory to
<FLOGO_HOME>/<version>/binand run:builder-<platform>_<arch> build -p linux/amd64 -f <path-to-the-.json-file>
This generates a linux app binary.
- Provide execute permission to the app binary:
chmod +x <app-binary>
- 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"]
- 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>
- Run the docker image locally to verify that all looks good:
docker run -it -p 9999:9999 <app-tag>
- Authenticate docker with the container registry where you want to push the docker image.
- 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> - 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. - To deploy your app on Kubernetes, run your app by creating a Kubernetes Deployment object. Follow these steps to do so:
- 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 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 - Create a Kubernetes deployment by running the following command:
kubectl apply -f deployment.yaml
- Create a YAML file. For example, the YAML file below describes a Deployment that runs the