为不同工作负载自定义 Lima 实例
您可以使用 YAML 和 yq
自定义 Lima 实例。
有关 yq 的更多信息,请参阅 yq 文档。
步骤
-
创建新实例
$ limactl create <instance>
-
编辑现有实例
$ limactl edit <instance>
一些可以编辑的内容
- 更改 CPU 数量、内存和磁盘大小
- 更改操作系统(Linux 发行版)
- 修改集群设置(Kubernetes 发行版)
- 同时运行容器工作负载和 Kubernetes 工作负载
另请参阅
目录
要查找实例目录(Dir
)的位置
limactl list <instance> --format '{{.Dir}}'
资源
可以为每个实例设置资源,也可以设置为全局默认值。
# CPUs
# 🟢 Builtin default: min(4, host CPU cores)
cpus: null
# Memory size
# 🟢 Builtin default: min("4GiB", half of host memory)
memory: null
# Disk size
# 🟢 Builtin default: "100GiB"
disk: null
要设置默认值,请编辑 Lima 主目录中的 _config/default.yaml
。
# The builtin defaults can be changed globally by creating a $LIMA_HOME/_config/default.yaml
# file. It will be used by ALL instances under the same $LIMA_HOME, and it
# will be applied on each `limactl start`, so can affect instance restarts.
# A similar mechanism is $LIMA_HOME/_config/override.yaml, which will take
# precedence even over the settings in an instances lima.yaml file.
# It too applies to ALL instances under the same $LIMA_HOME, and is applied
# on each restart. It can be used to globally override settings, e.g. make
# the mount of the home directory writable.
虚拟机和挂载
任何带有 ssh 的虚拟机(或服务器)都可以用于 Lima。
最兼容的挂载类型是 "reverse-sshfs"(来自 sshocker)。
您也可以选择使用 "qemu" 虚拟机和 "9p"(也称为 virtfs)挂载。
在 macOS 13+ 上,您还可以使用 "vz" 虚拟机和 "virtiofs" 挂载。
# VM type: "qemu" or "vz" (on macOS 13 and later).
# The vmType can be specified only on creating the instance.
# The vmType of existing instances cannot be changed.
# 🟢 Builtin default: "qemu"
vmType: null
# Mount type for above mounts, such as "reverse-sshfs" (from sshocker),
# "9p" (EXPERIMENTAL, from QEMU’s virtio-9p-pci, aka virtfs),
# or "virtiofs" (EXPERIMENTAL, needs `vmType: vz`)
# 🟢 Builtin default: "reverse-sshfs" (for QEMU), "virtiofs" (for vz)
mountType: null
容器
您可以在现有运行时的基础上安装容器引擎。
例如,您可以安装 Podman 引擎,或者安装 Docker 引擎。之后,您可以将套接字(socket)端口转发到主机的 Dir
。
Docker
portForwards:
- guestSocket: '/var/run/docker.sock'
hostSocket: '{{.Dir}}/sock/docker.sock'
/var/run/docker.sock
export DOCKER_HOST="unix://{{.Dir}}/sock/docker.sock"
Podman
portForwards:
- guestSocket: '/run/podman/podman.sock'
hostSocket: '{{.Dir}}/sock/podman.sock'
/run/podman/podman.sock
export CONTAINER_HOST="unix://{{.Dir}}/sock/podman.sock"
Kubernetes
您可以在现有容器引擎之上安装 Kubernetes。
例如,您可以为 Podman 使用 CRI-O,或为 Docker 使用 CRI-Dockerd。之后,您可以将 kubeconfig.yaml
文件复制到主机的 Dir
。
k3s.io
copyToHost:
- guest: '/etc/rancher/k3s/k3s.yaml'
host: '{{.Dir}}/copied-from-guest/kubeconfig.yaml'
deleteOnStop: true
/etc/rancher/k3s/k3s.yaml
export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml"
k8s.io
copyToHost:
- guest: '/etc/kubernetes/admin.conf'
host: '{{.Dir}}/copied-from-guest/kubeconfig.yaml'
deleteOnStop: true
/etc/kubernetes/admin.conf
export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml"