Skip to content

devspace

Devspace is a tool that makes kubernetes a lot easier.

Origin : https://devspace.sh/cli/docs/guides/ci-cd-integration

Advantages :

  • A graphical ui that just lets you pick pods etc.
  • One click to port forwarding and a bash shell.
  • Automatic generation of a random tag (extension) for Dockerhub
  • Generated yaml file, which can be of educational value as well.
  • Switching between developing and production is easier.

installation

installation
npm install -g devspace

If you don't have a local setup, do NOT install with sudo. Never use sudo npm ! If you must install it as root do it like this :

root install
curl -s -L "https://github.com/devspace-cloud/devspace/releases/latest" | sed -nE 's!.*"([^"]*devspace-linux-amd64)".*!https://github.com1!p' | xargs -n 1 curl -L -o devspace && chmod +x devspace;
sudo mv devspace /usr/local/bin;

image pull secret

Like with Jenkins, devspace needs to login to docker hub to push and pull images. This can be done by just doing a docker login before devspace commands. To see how to avoid having a plaintext password in your ~/.docker/config.json see docker-login-label{.interpreted-text role="ref"}.

To get the images from docker hub, Kubernetes relies on so-called image pull secrets. DevSpace can automatically create these secrets for you, if you configure createPullSecret: true for the respective image in your devspace.yaml.

devspace.yaml
version: v1beta9
images:
  app:
    image: kees/cheatsheets
    createPullSecret: true
    preferSyncOverRebuild: true
    ...

When you run devspace dev or deploy it adds the secret to your kubernetes service account. It is devspace that does this, but you can view it with kubernetes :

kubernetes
kubectl get serviceaccounts default -o yaml

apiVersion: v1
imagePullSecrets:
- name: devspace-auth-docker
kind: ServiceAccount
metadata:
    creationTimestamp: "2021-02-26T08:52:03Z"
    name: default
    namespace: default
    resourceVersion: "1276"
    selfLink: /api/v1/namespaces/default/serviceaccounts/default
    uid: 6c59c832-4087-4c83-90b7-71be426603f0
secrets:
- name: default-token-d42t4

development

It's called dev space for a reason.

development
devspace dev

This will deploy the image to the current context, start the ui if not running and open up a port forwarded webpage.

file synchronisation

devspace supports hot reloading of changed files, but it has to be configured in devspace.yaml default this se3ems to be generated :

devspace.yaml
dev:
  sync:
  - imageName: app
    excludePaths:
    - .git/
    uploadExcludePaths:
    - devspace.yaml
  interactive:
    defaultEnabled: true

Some things wrong with this are : defaultEnabled: true should be false or the app won't start but you get a bash prompt. This leads to an error with root paths (see troubleshooting section). You should add a non-root directory as containerPath. This example worked for the (old)doc project, it will synchronise the contents to docker when you run 'make html' :

devspace.yaml
dev
  sync:
  - imageName: app
    excludePaths:
    - .git/
    uploadExcludePaths:
    - devspace.yaml
    localSubPath: ./build/html/
    containerPath: /usr/local/apache2/htdocs/
  interactive:
    defaultEnabled: false

You basically use the same directories as in the Dockerfile :

deployment

context

You can alter the context more easily than by kubernetes, though it does change for both !

change context
devspace use context 

You could enter the context, but better just use the picklist because :

don't do this
devspace use m

This works for devspace, it detects minikube starts with m and the switch is working. But in kubernetes, ~/.kube/config Just says :

output
current-context: m

And now kubectl won't work. So either type correctly of just use the picklist.

troubleshooting

Encountered problems and solutions.

build hangs

This occurred while building the solver with devspace. Note that there maybe a login dialog hanging around, you should see Authentication successful for both subprojects :

successful login
[db] Info: Building image 'kees/db:sZmjRkE' with engine 'docker'
[db] Wait: Authenticating (hub.docker.com)
[db] Done: Authentication successful (hub.docker.com)
[app] Info: Building image 'kees/solver:hXAjfyk' with engine 'docker'
[app] Wait: Authenticating (hub.docker.com)
[app] Done: Authentication successful (hub.docker.com)

Also you can do a manual build, which shows all steps (devspace stays silent) :

manual docker build
docker build .
docker build db

You can see how long it takes and if there are problems. If all succeeds try devspace build again.

interactive mode

When running 'devspace dev' the interface does not start but you get a command prompt. Note that you can have that happen by default if you have this setting in devspace.yaml :

devspace.yaml
dev:
  ..
   interactive:
     defaultEnabled: true

You actually asked for it. Set it to false to disable and start the container.

container-path

The error encountered when running devspace dev :

error
[0:sync:app] Sync stopped
[0:sync:app] Restarting sync...
[0:sync:app] Start syncing                   
[0:sync:app] Sync started on /home/kees/projects/cheatsheet <-> . (Pod: default/cheatsheets-7848489f5b-wfgkm)
[0:sync:app] Error: Sync Error on /home/kees/projects/cheatsheet: Sync - connection lost to pod default/cheatsheets-7848489f5b-wfgkm: Error: you are trying to sync the complete container root (/). By default this is not allowed, because this usually leads to unwanted behaviour. Please specify the correct container directory via the `--container-path` flag or `.containerPath` option
Usage:
devspace-restart-helper sync upstream [flags]

See file synchronisation elsewhere in this document.