Docker Compose on Kubernetes with Okteto Stacks

This tutorial will show you how to develop an application using Okteto Stacks. Stacks are designed for developers who don't want to deal with the complexities of Kubernetes manifests or Helm charts.

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/stacks-getting-started
$ cd stacks-getting-started

The Sample App is a simple web application implemented using Python, with Redis for storage. The okteto-stack.yml file contains the Stack manifest of the Sample App:

name: voting-app
services:
vote:
public: true
image: okteto/vote:stacks
build: vote
replicas: 2
ports:
- 8080
resources:
cpu: 100m
memory: 128Mi
redis:
image: redis
ports:
- 6379
resources:
cpu: 100m
memory: 128Mi
storage: 1Gi
volumes:
- /data

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

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

$ okteto stack deploy --wait
โœ“ Successfully deployed stack 'voting-app'

The deploy command will create the necesary 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:

Step 2: Developing time!

Let's do 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 are happy with your changes, execute the following command:

$ okteto stack deploy --build
i Running your build in Okteto Cloud...
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
โœ“ Successfully deployed stack 'voting-app'

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 Stack in Okteto Cloud ๐Ÿš€.

Read the docs for the 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.