mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Dynamically determine default docker machine memory
Currently, if using `docker-machine` for k8s docker operations on a Mac, we'll create a VM with 4096MB of memory. The machine's RAM will be the same regardless of the memory available on the local machine. For example, if the user has 16GB on their local machine, the VM will still only have 4GB of RAM. Update the method for defining the `kube-dev` VM with `docker-machine`, so we give it access to 50% of the total RAM.
This commit is contained in:
parent
4c115a862b
commit
abee38cb4a
@ -26,7 +26,7 @@ DOCKER_OPTS=${DOCKER_OPTS:-""}
|
||||
DOCKER=(docker ${DOCKER_OPTS})
|
||||
DOCKER_HOST=${DOCKER_HOST:-""}
|
||||
DOCKER_MACHINE_NAME=${DOCKER_MACHINE_NAME:-"kube-dev"}
|
||||
readonly DOCKER_MACHINE_DRIVER=${DOCKER_MACHINE_DRIVER:-"virtualbox --virtualbox-memory 4096 --virtualbox-cpu-count -1"}
|
||||
readonly DOCKER_MACHINE_DRIVER=${DOCKER_MACHINE_DRIVER:-"virtualbox --virtualbox-cpu-count -1"}
|
||||
|
||||
# This will canonicalize the path
|
||||
KUBE_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd -P)
|
||||
@ -219,16 +219,28 @@ function kube::build::docker_available_on_osx() {
|
||||
|
||||
function kube::build::prepare_docker_machine() {
|
||||
kube::log::status "docker-machine was found."
|
||||
|
||||
local available_memory_bytes=$(sysctl -n hw.memsize 2>/dev/null)
|
||||
|
||||
local bytes_in_mb=1048576
|
||||
|
||||
# Give virtualbox 1/2 the system memory. Its necessary to divide by 2, instead
|
||||
# of multiple by .5, because bash can only multiply by ints.
|
||||
local memory_divisor=2
|
||||
|
||||
local virtualbox_memory_mb=$(( ${available_memory_bytes} / (${bytes_in_mb} * ${memory_divisor}) ))
|
||||
|
||||
docker-machine inspect "${DOCKER_MACHINE_NAME}" &> /dev/null || {
|
||||
kube::log::status "Creating a machine to build Kubernetes"
|
||||
docker-machine create --driver ${DOCKER_MACHINE_DRIVER} \
|
||||
--virtualbox-memory "${virtualbox_memory_mb}" \
|
||||
--engine-env HTTP_PROXY="${KUBERNETES_HTTP_PROXY:-}" \
|
||||
--engine-env HTTPS_PROXY="${KUBERNETES_HTTPS_PROXY:-}" \
|
||||
--engine-env NO_PROXY="${KUBERNETES_NO_PROXY:-127.0.0.1}" \
|
||||
"${DOCKER_MACHINE_NAME}" > /dev/null || {
|
||||
kube::log::error "Something went wrong creating a machine."
|
||||
kube::log::error "Try the following: "
|
||||
kube::log::error "docker-machine create -d ${DOCKER_MACHINE_DRIVER} ${DOCKER_MACHINE_NAME}"
|
||||
kube::log::error "docker-machine create -d ${DOCKER_MACHINE_DRIVER} --virtualbox-memory ${virtualbox_memory_mb} ${DOCKER_MACHINE_NAME}"
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user