Skip to main content

How it works using kubernetes

DevPod works the same with kubernetes as with Machines, the key difference is the secure tunnel is set up using the kubernetes control plane (e.g. kubectl ...) so an agent is not necessary to be run on the kubernetes node. Instead devpod-provider-kubernetes simply wraps the appropriate kubectl commands to start and connect a workspace using a devcontainer.

DevPod Architecture
DevPod - Container Diagram Kubernetes

DevPod often has to build workspaces even when an "image" is specified in .devcontainer.json. This is because the devcontainer can contain "features" the cause the Dockerfile to be extended. When this happens, or simply when "build" is used in .devcontainer.json, DevPod deploys an init container to the workspace that uses kaniko to first build your image (see #tutorials/reduce-build-times for more details on kaniko) then executes the container's entrypoint in the pod's main container. While building, if REGISTRY_CACHE has been specified in the context options, kaniko will download existing build layers from the registry to reduce the overall build time.

DevPod Architecture 2
DevPod - Component Diagram Kubernetes Build Process

Private registries​

DevPod gets registry credentials for a Kubernetes workspace in these ways:

  • Pull secret for the workspace image. With KUBERNETES_PULL_SECRETS_ENABLED (on by default), DevPod reads the credentials for the image's registry from the Docker config on your computer, including its credential helpers, and stores them in a pull secret that the workspace pod uses.
  • Forwarded Docker credentials. While DevPod builds the image in the pod, and in the dev container when SSH_INJECT_DOCKER_CREDENTIALS is on, registry requests are answered by the Docker credentials on your computer (see Credentials).
  • In-cluster credentials. When DevPod itself runs in a pod, it also uses the imagePullSecrets of the pod's service account, Google Artifact Registry and Container Registry credentials, and Azure Container Registry credentials when AZURE_CLIENT_ID and AZURE_TENANT_ID are set.

Amazon ECR has no built-in support. To use it, install docker-credential-ecr-login and add it to the Docker config (~/.docker/config.json) on your computer, or wherever DevPod runs:

{
"credHelpers": {
"123456789012.dkr.ecr.us-east-1.amazonaws.com": "ecr-login"
}
}

Using the kubernetes provider​

Add the provider, choose the namespace, and create a workspace. DevPod uses the cluster of your current kubectl context, or the one you give it:

devpod provider add kubernetes -o KUBERNETES_NAMESPACE=team-a
devpod provider add kubernetes --name staging -o KUBERNETES_CONTEXT=staging-cluster -o KUBERNETES_NAMESPACE=team-a --use=false
devpod up github.com/my-org/my-repo --provider staging

Options you will probably use (see all of them with devpod provider options kubernetes):

devpod provider set-options kubernetes \
-o DISK_SIZE=30Gi \
-o STORAGE_CLASS=fast-ssd \
-o RESOURCES=requests.cpu=2,limits.memory=8Gi \
-o NODE_SELECTOR=disktype=ssd \
-o INACTIVITY_TIMEOUT=2h

Namespaces​

With CREATE_NAMESPACE (on by default), DevPod creates the namespace when it doesn't exist. This also works on clusters that give you access to a namespace only once it exists, for example to whoever creates it: DevPod treats a forbidden lookup of the workspace's persistent volume claim in a namespace that doesn't exist as no workspace, creates the namespace, and waits up to a minute for access to it. To use a namespace that an administrator created for you, turn it off:

devpod provider set-options kubernetes -o CREATE_NAMESPACE=false -o KUBERNETES_NAMESPACE=team-a

Stopped and dead pods​

devpod stop stops the workspace's pod and keeps its persistent volume claim, and devpod up starts it again. If the pod is dead, because its phase is Failed, Succeeded or Unknown, its dev container has terminated, or it is being deleted (for example after the node restarted), devpod up recreates the pod, keeping the claim and so the workspace's files, instead of waiting for an agent that won't come:

devpod status my-workspace
devpod up my-workspace

Building images without Docker​

Kubernetes workspaces build their dev container in the pod, without a docker daemon, with the image ghcr.io/curityio/dockerless (built from the dockerless/ directory of this repository on kaniko). It checks the registries' TLS certificates. Use another image, or disable the build in the pod (then the workspace needs an image that doesn't need a build):

devpod provider set-options kubernetes -o DOCKERLESS_IMAGE=registry.example.com/dockerless:0.3.0
devpod provider set-options kubernetes -o DOCKERLESS_DISABLED=true

For a registry you trust on a network you trust, such as a registry cache inside the cluster that uses plain HTTP or a certificate the pod doesn't trust, allow it with DOCKERLESS_INSECURE. It applies to base images and the registry cache:

devpod context set-options -o REGISTRY_CACHE=registry.registry.svc.cluster.local:5000/devpod-cache
devpod provider set-options kubernetes -o DOCKERLESS_INSECURE=true