Today we’re featuring a blog from Pablo Chico de Guzmán at Okteto, who writes about how the developers’ love of Docker Compose inspired Okteto to create Okteto Stacks, a fully compatible Kubernetes backend for Docker Compose
It has been almost 7 years since the Docker Compose v1.0.0 release went live. Since that time, Docker Compose has become the dominant tool for local development environments. You run one command and your local development environment is up and running. And it works the same way on any OS, and for any application.
At the same time, Kubernetes has grown to become the dominant platform to deploy containers in production. Kubernetes lets you run containers on multiple hosts for fault tolerance, monitors the health of your applications, and optimizes your infrastructure resources. There is a rich ecosystem around it, and all major providers have native support for Kubernetes: GKE, AKS, EKS, Openshift…
We’ve interacted with thousands of developers as we build Okteto (a cloud-native platform for developers). And we kept hearing the same complaint: there’s a very steep learning curve when you go from Docker Compose to Kubernetes. At least, that was the case until today. We are happy to announce that you can now run your Docker Compose files in Kubernetes with Okteto!
Why developers need Docker Compose in Kubernetes
Developers love Docker Compose, and they love it for good reasons. A Docker Compose file for five microservices might be around 30 lines of yaml, but the same application in Kubernetes would be 500+ lines of yaml and about 10-15 different files. Also, the Docker Compose CLI rebuilds and redeploys containers when needed. In Kubernetes, you need additional tools to build your images, tag them, push them to a Docker Registry, update your Kubernetes manifests, and redeploy them. It’s too much friction for something that’s wholly abstracted away by Docker Compose.
But there are some use cases where running your Docker Compose files locally presents some challenges. For example, you might need to run dozens of microservices that exhausts your local CPU/Memory resources, you might need access to GPUs to develop a ML application, or you might want to integrate with a service deployed in a remote Kubernetes cluster. For these scenarios, running Docker Compose in Kubernetes is the perfect solution. This way, developers get access to on demand CPU/Memory/GPU resources, direct access to other services running in the cluster, and more realistic end-to-end integration with the cluster configuration (ingress controllers, SSL termination, monitoring tools, secret manager tools…), while still using the application definition format they know and love.
Docker Compose Specification to the rescue
Luckily, the Docker Compose Specification was open-sourced in 2020. This allowed us to implement Okteto Stacks, a fully compatible Kubernetes backend for Docker Compose. Okteto Stacks are unique with respect to other Kubernetes backend implementations of the Docker Compose Specification because they provide:
- In-cluster builds for better performance and caching behavior.
- Ingress Controller integration and SSL termination for public ports.
- Bidirectional synchronization between your local filesystem and your containers in Kubernetes.
Okteto’s bidirectional synchronization is pretty handy: it reloads your application on the cluster while you edit your code locally. It’s equivalent to mounting your code inside a container using Docker Compose host volumes, but for containers running in a remote cluster.
How to get started
Okteto Stacks are compatible with any Kubernetes cluster (you will need to install the Okteto CLI and a cluster-side Kubernetes application). But the easiest way to get started with Okteto Stacks is Okteto Cloud, the SaaS version of our cloud-native development platform.
To show the possibilities of Okteto Stacks, let’s deploy the famous Voting App. My team @Tutum developed the Voting App for the DockerCon keynote (EU 2015) to showcase the power of Tutum (later acquired by Docker that year). The demo gods were appeased with an offering of grapes that day. And I hope they are appeased again as you follow this tutorial:
First, install the Okteto CLI if you haven’t done it yet.
Next, configure access to your Okteto Cloud namespace. To do that, execute the following command:
$ okteto namespace Authentication required. Do you want to log into Okteto? [y/n]: y What is the URL of your Okteto instance? [https://cloud.okteto.com]: Authentication will continue in your default browser ✓ Logged in as cindy ✓ Updated context 'cloud_okteto_com' in '/Users/cindy/.kube/config'
Get a local version of the Voting App by executing the following commands:
$ git clone https://github.com/okteto/compose-getting-started $ cd compose-getting-started
Execute the following command to deploy the Voting App:
$ okteto stack deploy --wait ✓ Created volume 'redis' ✓ 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 Voting App. Go to the Okteto Cloud dashboard and you will get the URL of the application.
Now that the Voting App is running, let’s make a small change to show you the full development workflow.
Instead of our pet, let’s ask everyone to vote on our favorite lunch item. Open the “vote/app.py” file in your IDE and modify the lines 16-17. Save your changes.
def getOptions(): option_a = "Tacos" option_b = "Burritos"
Once you’re happy with your changes, execute the following command:
$ okteto up ✓ Images successfully pulled ✓ Files synchronized Namespace: cindy Name: vote * Serving Flask app 'app' (lazy loading) * Environment: development * Debug mode: on * Running on http://10.8.4.205:8080/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 139-182-328
Check the URL of your application again. Your code changes were instantly applied. No commit, build, or push required. And from this moment, any changes done from your IDE will be immediately applied to your application!
Go to the Okteto Stacks docs to learn more about our Docker Compose Kubernetes backend. We’re just starting, so we’d love to hear your thoughts on this.