What is the best practice to use kubernetes for local development?

5/11/2018

I am using docker containers and have docker-compose files for both local development and production environment. I want to try Google Cloud Platform for my new app and specifically Google Kubernetes Engine. My tools is Docker for Mac with Kubernetes on local machine.

It is super important for developers to be able to change code and to see changes live for local development.

Use cases:

  1. Backend developer make changes to basic Flask API (or whatever you use) and should see changes on reloaded app immediately.

  2. Frontend developer make changes to HTML layout and should see changes on web page immediately.

At the moment i am using docker-compose files to mount source code to local containers. But Kubernetes does not support relative paths to mount the source code.

Ideally i should be able to set the variable

Deployment.spec.templates.spec.containers.volumes.hostPath

as relative path to my repo. For example, in our team developers clone repo to this folders:

/User/BACKEND_developer/code/project_repo

/User/FRONTEND_developer/code/project_repo

Obviously you can't commit and build the image after every little change to the source code.

So what is the best practice for local development with Kubernetes? Do i need some additional tools to modify .yaml files for every developer?

-- Zhorzh Alexandr
docker
google-cloud-platform
kubernetes

2 Answers

5/11/2018

@tgogos is right. The best way to achieve your goal is to use Skaffold

It will rebuild container whenever it sees changes in source code.

Skaffold has a pluggable architecture that allows you to choose the tools in developer workflow that work best for you: Pluggability

-- Nick Rak
Source: StackOverflow

10/23/2018

A very promising approach for dynamic languages is the hybrid approach recently introduced by Skaffold, allowing to take advantage of the usual auto-reload mechanisms. You can define two set of files:

  • Changing a file on the first set triggers the full rebuild+push+deploy mechanism.
  • Changing a file on the second set only syncs the file between the local machine and the container.

Such an hybrid approach is well suited to a large class of technology stacks, like Node.js, React, Angular, Python, where you can use the native hot-reload mechanism for source code changes, and trigger the full rebuild only when it’s needed (for example, adding a dependency). This helps a lot in keeping the latency low.

I spoke about this in my recent talk at All Day Devops. Here there’s an example based on Node.JS.

-- mfornasa
Source: StackOverflow