Skip to content

Instantly share code, notes, and snippets.

@dims
Last active July 3, 2025 20:22
Show Gist options
  • Save dims/20a824aff15a9ceaa8b7190124ff3d3b to your computer and use it in GitHub Desktop.
Save dims/20a824aff15a9ceaa8b7190124ff3d3b to your computer and use it in GitHub Desktop.
lima configuration for a local environment to test things on macos
  • To create the vm:
limactl start containerd-ubuntu.yaml --yes
  • To get into the vm:
limactl shell --workdir /home/lima/containerd containerd-ubuntu
  • To build and install containerd:
/home/lima/build-containerd.sh
  • To kick the tires:
ctr version
crictl version
  • To stop and teardown the vm:
limactl stop -f containerd-ubuntu && limactl delete containerd-ubuntu
# Lima configuration for Ubuntu VM with containerd development setup
base: template://ubuntu-24.04
cpus: 4
memory: "8GiB"
disk: "100GiB"
user:
home: "/home/lima"
mounts:
- location: "{{.Home}}/go/src/github.com/containerd/containerd"
mountPoint: "/home/lima/containerd"
writable: true
ssh:
localPort: 60022
loadDotSSHPubKeys: true
containerd:
system: false
user: false
# Provisioning configuration
provision:
- mode: system
script: |
#!/bin/bash
set -e
echo "Starting containerd build setup..."
# Install packages
apt-get update -y
apt-get install -y \
git \
wget \
curl \
unzip \
gcc \
g++ \
make \
pkg-config \
libc6-dev \
linux-headers-generic \
htop \
psmisc \
libsystemd-dev \
libseccomp-dev \
btrfs-progs \
libdevmapper-dev \
gperf \
which
# Set up Go environment
ARCH=$(uname -m); if [ "$ARCH" = "x86_64" ]; then ARCH="amd64"; elif [ "$ARCH" = "aarch64" ]; then ARCH="arm64"; fi
curl -sL "https://dl.google.com/go/$(curl -s https://go.dev/VERSION?m=text | head -1).linux-${ARCH}.tar.gz" | sudo tar -C /usr/local -xzf -
VERSION="v1.32.0"
curl -sSL --fail --retry 5 https://storage.googleapis.com/k8s-artifacts-cri-tools/release/$VERSION/crictl-$VERSION-linux-$ARCH.tar.gz | sudo tar -xvzf - -C /usr/local/bin
echo 'export PATH=/usr/local/go/bin:$PATH' >> /home/lima/.bashrc
echo 'export PATH=$(go env GOPATH)/bin:$PATH' >> /home/lima/.bashrc
echo 'export GOPATH=/home/lima/go' >> /home/lima/.bashrc
# Set up environment for lima user
echo 'export TERM=vt100' >> /home/lima/.bashrc
echo 'cd /home/lima/containerd' >> /home/lima/.bashrc
# Create build script for containerd
cat > /home/lima/build-containerd.sh << 'BUILDEOF'
#!/bin/bash
set -e
export PATH=/usr/local/go/bin:$PATH
export PATH=$(go env GOPATH)/bin:$PATH
export GOPATH=/home/lima/go
echo "Go version: $(go version)"
cd /home/lima/containerd
echo "Building containerd from: $(pwd)"
# Run the setup scripts (adapted for Ubuntu)
echo "Installing dependencies..."
# Install seccomp
sudo -E "PATH=$PATH" script/setup/install-seccomp
# Install runc
sudo -E "PATH=$PATH" script/setup/install-runc
# Install CNI
sudo -E "PATH=$PATH" script/setup/install-cni
# Install protobuf
sudo rm -rf /usr/local/include/google /usr/local/readme.txt /go/src/usr/local/include/google || true
sudo rm -f /usr/local/bin/protoc /go/src/usr/local/bin/protoc || true
sudo -E "PATH=$PATH" script/setup/install-protobuf
sudo mkdir -p /go/src/usr/local/bin /go/src/usr/local/include
sudo mv /usr/local/bin/protoc /go/src/usr/local/bin/protoc
sudo mv /usr/local/include/google /go/src/usr/local/include/google
sudo rm -rf /home/lima/.cache/go-build/
# Build containerd
echo "Building containerd binaries..."
make binaries GO_BUILD_FLAGS="-mod=vendor"
# Install containerd
echo "Installing containerd..."
sudo -E "PATH=$PATH" make install
# Set up systemd service
echo "Setting up containerd service..."
if [ -f containerd.service ]; then
sudo cp containerd.service /etc/systemd/system/containerd.service
sudo systemctl daemon-reload
sudo systemctl enable containerd.service
sudo systemctl start containerd.service
echo "Containerd service started successfully!"
sudo systemctl status containerd.service --no-pager
fi
# for debugging convenience
sudo chown $USER:$USER /run/containerd/containerd.sock
echo 'runtime-endpoint: unix:///run/containerd/containerd.sock' | sudo tee /etc/crictl.yaml
echo "Containerd build and installation completed!"
BUILDEOF
chmod +x /home/lima/build-containerd.sh
chown lima:lima /home/lima/build-containerd.sh
# Create kernel modules configuration
tee /etc/modules-load.d/containerd.conf > /dev/null << 'MODEOF'
overlay
br_netfilter
MODEOF
# Create sysctl configuration
tee /etc/sysctl.d/99-kubernetes-cri.conf > /dev/null << 'SYSCTLEOF'
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
SYSCTLEOF
echo "Ubuntu VM setup complete for containerd development!"
echo ""
echo "To build and install containerd:"
echo "1. SSH into the VM: limactl shell containerd-ubuntu"
echo "2. Run the build script: ./build-containerd.sh"
echo ""
echo "The containerd source is mounted at: /home/lima/containerd"
echo "Go workspace is at: /home/lima/go"
echo ""
echo "Useful commands:"
echo "- build-containerd: Build and install containerd"
echo "- ctr: Run containerd CLI (with sudo)"
echo "- systemctl status containerd: Check containerd service status"
#!/bin/bash
set -e
crictl pull ubuntu
# Create pod sandbox config
cat > pod-config.json <<EOF
{
"metadata": {
"name": "ubuntu-sandbox",
"namespace": "default",
"attempt": 1,
"uid": "ubuntu-sandbox-uid"
},
"linux": {}
}
EOF
# Create container config
cat > container-config.json <<EOF
{
"metadata": {
"name": "ubuntu"
},
"image": {
"image": "ubuntu"
},
"command": [
"sleep",
"infinity"
],
"linux": {}
}
EOF
# Start the pod sandbox
POD_ID=$(crictl runp pod-config.json)
echo "Pod sandbox created: $POD_ID"
# Create the container inside the pod
CONTAINER_ID=$(crictl create "$POD_ID" container-config.json pod-config.json)
echo "Container created: $CONTAINER_ID"
# Start the container
crictl start "$CONTAINER_ID"
echo "Container started: $CONTAINER_ID"
# List pods and containers for verification
crictl pods
crictl ps
# Cleanup (uncomment if needed)
# crictl stop "$CONTAINER_ID"
# crictl rm "$CONTAINER_ID"
# crictl stopp "$POD_ID"
# crictl rmp "$POD_ID"
# rm -f pod-config.json container-config.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment