Skip to main content
Version: 4.x

Development with DevSpace

DevSpace allows you to develop applications directly inside a Kubernetes cluster.

The biggest advantages of developing directly inside Kubernetes is that your dev environment will be very similar to your production environment and you can have a much greater confidence that everything will work in production when shipping new features.

Start Development Mode

Run the following command to start your application in development mode:

devspace dev
DevSpace CLI - Development Mode

When running devspace dev, the dev section in devspace.yaml becomes important:

dev:
ports: # Port Forwarding Configuration
- imageName: app # Select pod & container by image name (reference to images section)
forward: # List of ports to forward
- port: 8080
open: # Open Browser (after deployment)
- url: http://localhost:8080
sync: # File Sync Configuration
- imageName: app # Select pod & container by image name (reference to images section)
uploadExcludePaths: # Never upload these files from local filesystem to the container
- Dockerfile
- .git
- devspace.yaml
onUpload: # Commands to execute after uploading files
restartContainer: true # Restart the container (uses the restart helper)

Running devspace dev will do the following:

  1. Build and deploy your application
  2. Stream the logs of all containers deployed during the deployment process
  3. Forward all ports specified in the dev.ports section in the devspace.yaml
  4. Sync all file changes according to the sync config in dev.sync, so you can restart your application inside the running container without having to rebuild images or redeploy anything

Deployment Workflow
DevSpace CLI - Deployment Workflow

Workflows

1. Edit Files & Restart

While devspace dev is running, your source code files will be synchronized between your local project folder and your containers running inside Kubernetes. This allows you to code with your favorite IDE or text editor without having to rebuild your images or redeploy your containers.

Try it and just edit a file!

You will see that the logs show how DevSpace restarts your application inside the container:

[app] ############### Restart container ###############

2. Open UI (in the browser)

When running devspace dev, DevSpace starts a client-only UI for Kubernetes. You can see that in the output of devspace dev which should contain a log line similar to this one:

#########################################################
[info] DevSpace UI available at: http://localhost:8090
#########################################################

By default, DevSpace starts the development UI on port 8090 but if the port is already in use, it will use a different port. If devspace dev is running, you can open the link shown in the devspace dev logs, e.g. http://localhost:8090

You can also start the UI without running devspace dev using this command:

devspace ui

Follow this guide to learn more about the functionalities of the DevSpace UI for Kubernetes development.

DevSpace CLI - Development UI
Runs on Localhost

The UI of DevSpace is open-source just like the rest of the CLI and it runs entirely on localhost.

3. Use Port Forwarding

While devspace dev is running, you can access your application via localhost:[PORT] because DevSpace starts port forwarding for all ports specified in the dev.ports section of your project's devspace.yaml.

Port forwarding also allows you to attach to remote debuggers if you package them into your development Docker image. This allows you to set breakpoints in your IDE and the code execution will break inside the remote container while you can debug in your IDE.

Port Detection

When running devspace init, DevSpace detects all ports within your Dockerfile (i.e. EXPOSE [PORT] lines) and automatically configures forwarding for them when creating the devspace.yaml.

Learn more about how to configure port forwarding.

Notes

danger

It is highly discouraged to run devspace dev multiple times in parallel because multiple instances of port forwarding and file synchronization will disturb each other. Instead:

  • Run devspace enter to open additional terminal sessions without port forwarding and file sync
  • Run devspace logs to start log streaming without port forwarding and file sync
  • Run devspace sync to sync files on-demand without starting port forwarding etc.
  • Run devspace ui to open the localhost development UI in the browser