Skip to main content
Version: 5.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 much greater confidence that everything will work in production when shipping new features.

DevSpace - Development Mode

Kube-Context & Namespace

To develop and deploy your project with DevSpace, you need a valid kube-context because DevSpace uses the kube-config file just like kubectl or helm.

Local Clusters

Local clusters run on your local dev machine and include: minikube, kind, k3s, mikrok8s etc.

If you want to deploy to a local Kubernetes cluster, make sure your current kube-context points to this cluster and tell DevSpace which namespace to use:

devspace use context                  # to select the right k8s cluster
devspace use namespace my-namespace # will be automatically created during deployment
Kube-Context Namespace

Running the command above will change the default namespace of your kube-context, i.e. instead of using the default namespace, kubectl and other tools will now use a different namespace when working with this kube-context. That also means, you will not always need to use the --namespace / -n flag.

Start Development Mode

Run the following command to start the development mode:

devspace dev

Running devspace dev will do the following:

  1. Deploy your application according to your deployments section
  2. Replace pods according to your dev.replacePods section
  3. Forward ports specified in the dev.ports section
  4. Sync file changes between your local project directory and the k8s pods according to the dev.sync section
  5. Open a terminal according to the dev.terminal section, so you start your application and work inside your container

Once the terminal session starts, run the command to start your application:

npm start  
# or: npm run dev
# or: yarn start

Workflows

1. File Sync

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!

2. DevSpace UI

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 - 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.

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