DevSpace Documentation

repository·main·Indexed 26 days ago

https://github.com/devspace-sh/devspace

A client-only CLI tool for cloud-native development that streamlines building, deploying, and debugging applications directly in Kubernetes. DevSpace features hot-reloading via bi-directional file synchronization, declarative workflows using devspace.yaml, and automated tasks for image building, tagging, and port-forwarding. It is compatible with any Kubernetes cluster accessible via kubectl, including local and managed cloud clusters.

Tokens
207K
Snippets
475
Records
1.6K
Agent score
79%

What's inside DevSpace

  1. Introduction to DevSpace

    main

    DevSpace is an open-source, client-only developer tool designed for Kubernetes-based cloud-native development. It allows developers to build, test, and debug applications directly inside Kubernetes clusters.

    Key capabilities include:

    • Hot Reloading: High-performance, bi-directional file synchronization that updates running containers without rebuilding images or restarting containers.
    • Declarative Workflows: All deployment and development workflows are codified in a devspace.yaml file, allowing workflows to be versioned with your code and shared across teams.
    • Automation: Automates repetitive tasks such as parallel image building, automatic tagging, deployment of entire application stacks, port-forwarding, and log streaming.
    • Team Standardization: Enables DevOps experts to define workflows in devspace.yaml so that other developers can deploy the entire project using a single command.
  2. Overview of DevSpace

    main

    DevSpace is a client-only developer tool designed for cloud-native development with Kubernetes. It allows you to build, test, and debug applications directly inside Kubernetes clusters. Key features include:

    • Hot Reloading: Updates running containers without rebuilding images or restarting containers via high-performance, bi-directional file synchronization.
    • Declarative Workflows: Store all build, deploy, and dependency workflows in a single devspace.yaml file to version and share with your team.
    • Automated Tasks: Automates repetitive tasks like parallel image building, automatic tagging, port-forwarding, and log streaming.
    • Cluster Compatibility: Works with any Kubernetes cluster accessible via kubectl, including local clusters (minikube, k3s, kind, Docker Desktop) and managed cloud clusters (GKE, EKS, AKS, Digital Ocean).
  3. Supported Build Engines in DevSpace

    main

    DevSpace supports several build engines for container image construction. You can explicitly configure which engine to use for a specific image in your devspace.yml configuration.

    Supported engines include:

    • Docker: Uses the standard Docker daemon.
    • Buildkit: Uses the BuildKit backend for advanced features.
    • Kaniko: A tool to build container images from a Dockerfile inside a container or Kubernetes cluster without a Docker daemon.
    • Custom: Allows you to define your own build logic.
  4. Understand the files created by `devspace init`

    main

    Running devspace init introduces three changes to your project directory:

    1. devspace.yaml: The primary configuration file that defines how your project is built, deployed, and developed.
    2. devspace_start.sh: A script used to display information to the user when a development container terminal is opened.
    3. .devspace/ folder: A local directory used by DevSpace for internal information and caching to speed up operations (this folder is automatically added to .gitignore).
  5. Configure Dev Workflows and Connections

    main

    Dev connections define how your local machine and IDE connect to the dev container running in Kubernetes. You can configure several types of connections to improve your development experience:

    • Bi-directional file sync: Keeps files on your localhost and inside the container's main working directory in sync.
    • Port forwarding (and reverse port forwarding): Allows you to access services inside the dev container via localhost on your local machine (and vice versa).
    • Terminal connection: Connect your local terminal to the dev container by starting a new session, attaching to the container's entrypoint process, or streaming container logs.
    • SSH injection: Injects an SSH server into the dev container, enabling remote environment capabilities for IDEs like VS Code.
    • Auto-restart: Enables a hot-reloading experience by automatically restarting the container without requiring a full image rebuild.
    • Proxy commands: Makes local commands (e.g., kubectl) accessible inside the container without needing to copy credentials into the container environment.
    • Auto-open URLs: Automatically opens specific URLs in your browser once the dev container is ready.
  6. Architecture and Workflow

    main
    DevSpace operates as a single binary CLI tool running on your local machine. It does not require a server-side component. Instead, it communicates directly with your Kubernetes cluster using your existing kube-context, behaving similarly to kubectl.
  7. Manage DevSpace variables and profiles

    main

    DevSpace allows you to manage environment variables and profiles dynamically:

    • Override variables: Use --var=KEY=VALUE to pass variables during execution.
    • Persist variables: Use --restore-vars to load variables from Kubernetes and --save-vars to save them back to Kubernetes. The storage secret is controlled by --vars-secret (defaults to devspace-vars).
    • Apply profiles: Use -p or --profile to specify profiles. You can chain profiles using --profile-parent to ensure base profiles are applied before your target profile.
  8. Define and use Custom Commands in devspace.yaml

    main

    You can define a set of reusable scripts in the commands section of your devspace.yaml file. This allows team members to execute complex or frequently used commands without needing to know the underlying details. Custom commands can execute any shell script, run other devspace commands, or set environment variables. They behave similarly to the scripts section in a Node.js package.json.

    # File: devspace.yaml
    images:
      default:
        image: john/backend
    
    commands:
      debug-backend: |- 
        devspace dev $@
  9. Build Images with BuildKit

    main

    You can use BuildKit as a build engine to build images either locally or inside your Kubernetes cluster without requiring a Docker daemon.

    To use BuildKit, you must have either Docker or the buildx CLI installed locally. If you are using the in-cluster build functionality, a running Docker daemon is not required; only the CLI tools are needed.

    To enable BuildKit for a specific image, define the buildKit field in your devspace.yaml.

    images:
      backend:
        image: john/appbackend
        buildKit: {}
  10. Use Config Expressions in devspace.yaml

    main

    Config expressions allow you to load devspace.yaml dynamically by specifying $( my bash expression ). The stdout of the bash expression is used as the value for the option or the entire section.

    Expressions are evaluated after variables and profiles are applied. They run in a POSIX-compatible shell (via a Go-based shell implementation) that works across all operating systems.

    Variables are resolved both before and after expressions, meaning you can load a file via an expression that contains variables which will then be resolved.