Pre-load Workspace Images on Agents
Table of Contents
To optimize autoscaling of Docker agents, you can pre-load workspace images on your agents so that you don’t have to wait for Kasm to pull your workspace images after the agent is provisioned. You can configure this during the creation of your Linux VM template, irrespective of the VM provider.
Create a Kasm API key
Go to your Kasm Admin Dashboard -> “Settings” -> “Developers”
Click “Add API Key”
Give your API key a name
Enable
Read Only
Set an Expiration date for your API key (Optional)
Create API key to view images
This will generate your
API KEY
andAPI KEY SECRET
. Save them securely as you cannot see these values againSave your API Key and Secret
Next, give your API key the
Images View
permission and click “Submit”Give “Images View” permission to your API key
Fetch and pull your Workspace Images
Run the following bash script that does the following:
Install Docker CE (based on instructions from https://docs.docker.com/engine/install/ubuntu)
Export Kasm Variables (
KASM_HOST
,API_KEY
,API_KEY_SECRET
)Fetch the Workspaces Images list from your Kasm deployment
Pull the Workspace Images with
docker pull
This script assumes you are running Ubuntu OS on your agents as listed here. If you are using a different Linux distro, make sure to change the docker installation logic accordingly.
Make sure to replace following variables with the actual values from your Kasm deployment:
KASM_HOST
: The IP/FQDN of your Kasm deployment. If you’re using a multi-server setup, this is the IP/FQDN of your Kasm Web App role.API_KEY
: The API Key you generated earlier.API_KEY_SECRET
: The API Key Secret you generated earlier.
# Install Docker on Ubuntu (ref: https://docs.docker.com/engine/install/ubuntu/)
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce
# Kasm API variables
export API_KEY=<Your Kasm API Key>
export API_KEY_SECRET=<Your Kasm API Key Secret>
export KASM_HOST=<Your Kasm IP/FQDN>
# Fetch and pull all images
curl -sk -X POST "https://${KASM_HOST}/api/admin/get_images" \
-H "Content-Type: application/json" \
-d "{\"api_key\":\"${API_KEY}\",\"api_key_secret\":\"${API_KEY_SECRET}\"}" \
| jq -r '.images[] | select(.name != null) | .name' \
| while read -r image_name; do
echo "Pulling image: $image_name"
sudo docker pull "$image_name"
done
After pulling all the required workspace images, you can shut down the VM and create a template from it. When Kasm triggers autoscaling and provisions new agent VMs from this template, the workspace images will already be pre-loaded. This eliminates the delay caused by image downloads during provisioning, resulting in faster workspace launches.