Configure Terminal
DevSpace provides three modes for connecting your terminal to the dev container:
- Start a new terminal session and connect to it (think
kubectl exec -it [pod] -c [container]
) - Attach to the dev container's entrypoint process (i.e. PID 1 inside the container, think
kubectl attach [pod] -c [container]
) - Stream the dev container's logs (i.e. stdout of the container, think
kubectl logs [pod] -c [container]
)
Beware that you can only enable one of the three modes since you only have one terminal locally.
However, if you open a second terminal locally, you could run on-demand commands such as devspace enter
, devspace attach
, or devspace logs
which may achieve similar results but they will not do any implicit patches to your dev container.
Alternatively, the pipelines in your devspace.yaml
could introduce custom flags such as --terminal
or --attach
to let the user pick which mode to enable.
Start New Terminal Session
Using the dev.*.terminal
section in the devspace.yaml
, you can tell DevSpace to start a terminal session inside the dev container and then connect to it as part of the start_dev
process:
deployments:
app:
helm:
values:
containers:
- image: myregistry/myapp
dev:
my-dev:
imageSelector: myregistry/myapp
terminal: {}
Under the hood DevSpace will replace the running pod and apply the following changes, before actually starting a terminal to it:
- Remove
readinessProbes
,startupProbes
&livenessProbes
- Change the entrypoint of the container to
sleep 100000
only ifdev.*.command
anddev.*.args
are not specified, otherwise it will respect these configs
If you do not want DevSpace to replace the pod with a modified version, use disableReplace: true
DevSpace will also try to install and use screen to start the terminal session, as this allows you to reconnect to your existing session after losing connection. You can disable this via the disableScreen: true
option
Attach To Entrypoint
Attach can be used to attach to a process that is already running inside an existing container, typically the PID 1 process (container entrypoint).
Under the hood this mode is effectively calling kubectl attach
.
deployments:
my-deployment:
helm:
values:
containers:
- image: ubuntu
dev:
my-dev:
imageSelector: ubuntu
attach: {}
Under the hood DevSpace will replace the running pod and apply the following changes, before actually attaching to it:
- Remove
readinessProbes
,startupProbes
&livenessProbes
- Add
stdin: true
andtty: true
to the container spec
If you don't want DevSpace to replace the pod with a modified version, use disableReplace: true
Stream Logs
Instead of starting an interactive terminal session or attaching to the container, you can also just stream the logs of the dev container.
The benefit of log streaming may be that you can stream the logs of multiple dev containers in parallel whereas a terminal connection can only be established to a single container at the time.
To configure log streaming, set the dev.*.logs
field in the `devspace.yaml for the respective dev container:
dev:
my-dev-1:
imageSelector: ...
logs: {}
my-dev-2:
imageSelector: ...
logs: {}
my-dev-3:
imageSelector: ...
logs:
lastLines: 100
DevSpace will continously check what pods match the given selectors and start or end log streaming accordingly.
Config Reference
terminal
required
Terminal allows you to tell DevSpace to open a terminal with screen support to this container
terminal
required command
required string
Command is the command that should be executed on terminal start.
This command is executed within a shell.
command
required string workDir
required string
WorkDir is the working directory that is used to execute the command in.
workDir
required string enabled
required boolean false
If enabled is true, DevSpace will use the terminal. Can be also
used to disable the terminal if set to false. DevSpace makes sure
that within a pipeline only one dev configuration can open a terminal
at a time and subsequent dev terminals will fail.
enabled
required boolean false disableReplace
required boolean false
DisableReplace tells DevSpace to not replace the pod or adjust its settings
to make sure the pod is sleeping when opening a terminal
disableReplace
required boolean false disableScreen
required boolean false
DisableScreen will disable screen which is used by DevSpace by default to preserve
sessions if connections interrupt or the session is lost.
disableScreen
required boolean false disableTTY
required boolean false
DisableTTY will disable a tty shell for terminal command execution
disableTTY
required boolean false attach
required
Attach allows you to tell DevSpace to attach to this container
attach
required enabled
required boolean false
Enabled can be used to enable attaching to a container
enabled
required boolean false disableReplace
required boolean false
DisableReplace prevents DevSpace from actually replacing the pod with modifications so that
the pod starts up correctly.
disableReplace
required boolean false disableTTY
required boolean false
DisableTTY is used to tell DevSpace to not use a TTY connection for attaching
disableTTY
required boolean false