Deploying a Compose-based app to a Kubernetes cluster

MKE enables deploying Docker Compose files to Kubernetes clusters. Starting in Compose file version 3.3, you use the same docker-compose.yml file that you use for Swarm deployments, but you specify Kubernetes workloads when you deploy the stack. The result is a true Kubernetes app.

Get access to a Kubernetes namespace

To deploy a stack to Kubernetes, you need a namespace for the app’s resources. Contact your MKE administrator to get access to a namespace. In this example, the namespace is called labs.

Create a Kubernetes app from a Compose file

In this example, you create a simple app, named “lab-words”, by using a Compose file. This assumes you are deploying onto a cloud infrastructure. The following YAML defines the stack:

version: '3.3'

    image: dockersamples/k8s-wordsmith-web
     - "8080:80"

    image: dockersamples/k8s-wordsmith-api
      replicas: 5

    image: dockersamples/k8s-wordsmith-db
  1. In your browser, log in to https://<mke-url>. Navigate to Shared Resources > Stacks.

  2. Click Create Stack to open up the “Create Application” page.

  3. Under “Configure Application”, type “lab-words” for the application name.

  4. Select Kubernetes Workloads for Orchestrator Mode.

  5. In the Namespace drowdown, select “labs”.

  6. Under “Application File Mode”, leave Compose File selected and click Next.

  7. Paste the previous YAML, then click Create to deploy the stack.

Inspect the deployment

After a few minutes have passed, all of the pods in the lab-words deployment are running.

To inspect the deployment:

  1. Navigate to Kubernetes > Pods. Confirm that there are seven pods and that their status is Running. If any pod has a status of Pending, wait until every pod is running.

  2. Next, select Kubernetes > Load balancers and find the web-published service.

  3. Click the web-published service, and scroll down to the Ports section.

  4. Under Ports, grab the Node Port information.

  5. In a new tab or window, enter your cloud instance public IP Address and append :<NodePort> from the previous step. For example, to find the public IP address of an EC2 instance, refer to Amazon EC2 Instance IP Addressing. The app is displayed.

See also