Simplify Remote Development with Coder, Docker-in-Docker (dind), and Sysbox
--
In today’s fast-paced and globally connected world, remote development has become a norm for many software engineers and teams.
Managing consistent development environments across multiple machines can be challenging, but thankfully, there are great tools available to simplify the process.
In this blog post, I’ll explain how you can create your remote development workflow using Coder, Docker-in-Docker (dind), and Sysbox.
Tools explained
Coder
…is an open-source platform that allows you to develop code remotely using a web-based IDE. It provides a seamless interface for remote development while ensuring consistency and collaboration across teams.
Sysbox
… is a powerful container runtime that extends the capabilities of Docker. It enables running Docker-in-Docker with improved performance, security, and compatibility. By leveraging sysbox, you can simplify the setup and management of dind containers.
Requirements
In order to set up and run remote development environments using Coder and Sysbox, there are a few prerequisites you need to fulfill. One of the essential requirements is to have a running Kubernetes cluster in place which is ready to be used.
Another essential requirement is Helm.
Disclaimer: I only tested this using Rancher Kubernetes Engine 2 (RKE2).
Installation
Sysbox
Step 1: Label the Node To designate a specific node where you want to install Sysbox. Use the following command to label the desired node(s) with
kubectl label nodes my-node-a sysbox-install=yes
Replace my-node-a
with the name of the node where you want to install Sysbox.
Step 2: Apply the Sysbox Installation Manifest Once the node is labeledUse the following command to apply the manifest:
kubectl apply -f https://raw.githubusercontent.com/nestybox/sysbox/master/sysbox-k8s-manifests/sysbox-install.yaml
Step 3: Verifying the Installation After applying the manifest, you can verify the Sysbox installation by checking the status of the Sysbox pods. Use the following command:
$ kubectl get pods -n kube-system |grep sysbox
sysbox-deploy-k8s-jhsrj
$ kubectl logs -n kube-system -f sysbox-deploy-k8s-jhsrj
[...]
The k8s runtime on this node is now CRI-O.
Sysbox installation completed.
Done.
Coder
Install Coder by following the official documentation. Visit the Coder documentation website for the latest Kubernetes installation guide. Review the requirements, follow the instructions, and adapt them to your environment if needed. After completing the installation, verify that Coder is running correctly on your cluster. The official documentation provides detailed guidance specific to installing Coder on Kubernetes, ensuring a reliable setup.
Setup your Workspace
I provide a mostly pre-provided template for Coder which can be used as a starting point. It can be customized based on your specific requirements and configurations. It demonstrates how to create a Pod with the necessary setup for running a workspace in Coder, including the use of the Sysbox container runtime and starting the Coder agent within the container.
See here how you can add templates to Coder using their official documentation.
NOTE: Using the mingfang/k8s
Kubernetes provider in the provided template is necessary because the official Kubernetes provider lacks the runtime_class_name
key.
terraform {
required_providers {
coder = {
source = "coder/coder"
}
k8s = {
source = "mingfang/k8s"
}
}
}
data "coder_workspace" "me" {}
resource "coder_agent" "main" {
os = "linux"
arch = "amd64"
dir = "/home/coder"
}
resource "k8s_core_v1_pod" "dev" {
count = data.coder_workspace.me.start_count
metadata {
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
namespace = var.workspaces_namespace
annotations = {
"io.kubernetes.cri-o.userns-mode" = "auto:size=65536"
}
}
spec {
# Use Sysbox container runtime (required)
runtime_class_name = "sysbox-runc"
# Run as root in order to start systemd (required)
security_context {
run_asuser = 0
fsgroup = 0
}
containers {
name = "dev"
env {
name = "CODER_AGENT_TOKEN"
value = coder_agent.main.token
}
image = "codercom/enterprise-base:ubuntu"
command = ["sh", "-c", <<EOF
# Start the Coder agent as the "coder" user
# once systemd has started up
sudo -u coder --preserve-env=CODER_AGENT_TOKEN /bin/bash -- <<-' EOT' &
while [[ ! $(systemctl is-system-running) =~ ^(running|degraded) ]]
do
echo "Waiting for system to start... $(systemctl is-system-running)"
sleep 2
done
${coder_agent.main.init_script}
EOT
exec /sbin/init
EOF
]
}
}
}
Lastly deploy the workspace based on the newly created Coder template.
After launching your workspace you should be able to see something similar to the following screenshot where you can choose how to access it.
I tried docker ps
and docker docker run -ti debian:11-slim bash
right away to verify everything works as expected.
Conclusion
By combining the power of Coder, Docker-in-Docker and Sysbox, remote development becomes significantly simpler.
By following the installation steps, you can establish a robust remote development environment on your Kubernetes cluster.
Enjoy the benefits of remote development with enhanced ease and efficiency!
Cheers!