Skip to main content

Docker Compose on Kubernetes with Okteto Stacks

This tutorial will show you how to develop an application using Okteto Stacks. Okteto Stacks are for developers who don't want to deal with the complexities of Kubernetes manifests. Okteto Stacks implement and extend the Compose Specification to make it easy to deploy containers in Kubernetes.

Prerequisites

Step 1: Deploy the Sample App

Get a local version of the Sample App by executing the following commands:

$ git clone https://github.com/okteto/compose-getting-started
$ cd compose-getting-started

The Sample App is a simple web application implemented using Python, with Redis for storage. The docker-compose.yml file defines the components of the Sample App:

services:
vote:
build: vote
scale: 2
ports:
- 8080:8080
redis:
image: redis
ports:
- 6379
volumes:
- redis:/data
volumes:
redis:

The equivalent Kubernetes manifests would have more than 300 lines of yaml!

Deploying the Sample App is as simple as executing this command:

$ okteto stack deploy --wait
✓ Deployed service 'vote'
✓ Deployed service 'redis'
✓ Stack 'compose-getting-started' successfully deployed

The deploy command will create the necessary deployments, services, persistent volumes, and ingress rules needed to run the Sample App. Cool no 😎?

Open your browser and go to the URL of the application. You can get the URL by logging into Okteto Cloud and clicking on the application's endpoint:

Okteto stack UI

Step 2: Developing time!

Let's make some changes to our application. For example, open the vote/app.py file in your IDE and modify the voting options on lines 16-17. Save your changes.

def getOptions():
option_a = "Local development"
option_b = "Cloud development"

Once you're happy with your changes, execute the following command:

$ okteto stack deploy --build
i Running your build in tcp://buildkit.cloud.okteto.net:1234...
i Building image for service 'vote'...
[+] Building 4.2s (13/13) FINISHED
=> importing cache manifest from registry.cloud.okteto.net/pchico83/ vote:okteto 1.0s
=> [internal] load build definition from buildkit-630371997 0.4s
=> => transferring dockerfile: 524B 0.4s
=> [internal] load .dockerignore 0.3s
=> => transferring context: 2B 0.3s
=> [internal] load metadata for docker.io/library/python:3-slim 0.7s
=> [internal] load build context 0.6s
=> => transferring context: 6.04kB 0.6s
=> [1/6] FROM docker.io/library/python:[email protected]:c0281d8fe99edff517fcc748f088bc51822ae660bac9e4aba76a81fa987fe9e8 0.0s
=> => resolve docker.io/library/python:[email protected]:c0281d8fe99edff517fcc748f088bc51822ae660bac9e4aba76a81fa987fe9e8 0.0s
=> CACHED [2/6] WORKDIR /src 0.0s
=> CACHED [3/6] RUN pip install --upgrade pip 0.0s
=> CACHED [4/6] ADD requirements.txt requirements.txt 0.0s
=> CACHED [5/6] RUN pip install -r requirements.txt 0.0s
=> CACHED [6/6] ADD . /src 0.0s
=> exporting to image 1.8s
=> => exporting layers 0.0s
=> => exporting manifest sha256:23567b4fef520ef1fb356cacad163e019c06c5942a991fc76f12f0cbab7b3b3a 0.0s
=> => exporting config sha256:a424f508b9602ec44193c2c6408107d4d4c8f7f7eb71828c884a2c6feb574ea6 0.0s
=> => pushing layers 1.1s
=> => pushing manifest for registry.cloud.okteto.net/pchico83/vote:okteto 0.6s
=> exporting cache 0.2s
=> => preparing build cache for export 0.2s
✓ Image for service 'vote' successfully pushed
✓ Deployed service 'vote'
✓ Deployed service 'redis'
✓ Stack 'compose-getting-started' successfully deployed

okteto stack deploy --build automatically builds a new image tag using the Okteto Build Service, pushes it to the Okteto Registry, and redeploys your application with the new image tag. In a matter of seconds, your changes are running in the Cloud 💥!

Next steps

Congratulations, you just developed your first application in Okteto Cloud 🚀.

Read the docs for the Okteto Stack Manifest and the available Okteto Stack CLI commands to learn more about developing your application using Stacks.

Head over to our getting started guides for Go, ASP.NET, Java, Node.js, PHP, Python, or Ruby to see how to configure Okteto to live-update your application with different programming languages and debuggers.