DEV Community

Gbeminiyi 'Telo Briggs' Oshoba
Gbeminiyi 'Telo Briggs' Oshoba

Posted on • Originally published at kerosinecoding.com on

Deploy to Kubernetes in 5 minutes with Docker Compose and Okteto Cloud

header

Why developers need Docker Compose in Kubernetes


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.

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.

A docker-compose manifest is a configuration manifest file for listing and configuring single or multiple application services to be deployed. Like Kubernetes manifests or Helm charts, docker-compose is supported as a manifest for application deployment on Okteto.

teleprescense

Docker Compose, Kubernetes & Okteto Stacks

Okteto Stacks is 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.

For a more beginner friendly quickstart there is a handy tutorial hosted by the Docker Team here.

In this tutorial, you’ll learn how to deploy a Fullstack Invoice Management App called Kerosine Invoicing to Okteto Cloud by using a docker compose manifest. Quickly grab the code here

How to get started

In order to follow this tutorial, the following prerequisites must be met:

  • The latest stable version of Node installed on your machine
  • Good knowledge of the Nodejs and Docker
  • Docker compose installed.
  • Okteto CLI installed.

To show the possibilities of Okteto Stacks, let’s deploy our Invoice Management App, Kerosine Invoicing.

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

$ git clone https://github.com/ocdkerosine/kerosine-invoicing.git

$ cd kerosine-invoicing

$ okteto stack deploy --wait

i Using ocdkerosine @ cloud.okteto.com as context
! The following fields are not currently supported and will be ignored: 
    - networks
    - services[kerosine-invoice-frontend, kerosine-invoice-backend].networks
    - volumes[api-data].driver
Help us to decide which fields to implement next by filing an issue in https://github.com/okteto/okteto/issues/new
✓ Created volume 'api-data'
✓ Deployed service 'kerosine-invoice-frontend'
✓ Deployed service 'kerosine-invoice-backend'
✓ Stack 'kerosine-invoicing' successfully deployed
i Endpoints available:
   - https://kerosine-invoice-backend-ocdkerosine.cloud.okteto.net/
   - https://kerosine-invoice-frontend-ocdkerosine.cloud.okteto.net/
Enter fullscreen mode Exit fullscreen mode

The deploy command will create the necessary deployments, services, persistent volumes, and ingress rules needed to run the Kerosine Invoicing App. Go to the Okteto Cloud dashboard and you will get the URL of the application… or maybe just pick it up from your console.

Dashboard :

dashboard

Live App:

live app

Sidebar:

It is at this point I would like to obligatorily pull you away from the action to speak on my environment setup and tell you the inspiration behind it. I code using VS Codium(open source binary release of vscode without Microsoft telemetry) on Parrot OS, Linux. Parrot is a security and pen-testing based OS. Its popular rival is Kali Linux, the OS in which I learnt the bread and butter of hacking and Linux Administration. But why? Because trackers are using your information for purposes that don’t protect your self interest. Find out how you can protect yourself from the PrivacyTools.io site here.

privacy tools

Moving On

We have successfully deployed our application to the Kubernetes development platform, Okteto, using docker-compose as below:

moving on

Local Development

Now that the Kerosine Invoicing App is running on the cloud (production), let’s make a small change (on local pc) to show you the full development workflow.

Open the “frontend/public/index.html” file in your IDE and change the line 14. Save your changes.

<title>Kerosine Invoice App</title>
Enter fullscreen mode Exit fullscreen mode

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

okteto up
Enter fullscreen mode Exit fullscreen mode

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 all thanks to Telepresence!

local development

Conclusion

By using docker-compose with Okteto, you’re able to get all the benefits of developing with Kubernetes, such as using monitoring tools, platform services like secret management tools, and taking ownership of the release pipeline, but without the hassle of needing to learn Kubernetes.

The post Deploy to Kubernetes in 5 minutes with Docker Compose and Okteto Cloud first appeared on Kerosine Coding.

Top comments (0)