From e910fd317d4a542ec87f48934b52536fe91cde53 Mon Sep 17 00:00:00 2001 From: Abhinav Gianey Date: Tue, 6 Jul 2021 15:06:15 -0400 Subject: [PATCH] Add k3d support and deprecate minikube (#89) * Add k3d support and deprecate minikube --- Dockerfile | 3 + README.md | 89 ++------ aladdin-container.sh | 25 +-- aladdin.sh | 206 +++++------------- aladdin/bash/container/cluster/cluster | 2 +- .../get-dashboard-url/get-dashboard-url | 31 --- aladdin/bash/container/host/host | 3 +- aladdin/bash/container/test-local/test-local | 2 +- .../container/test-local/test-refresh.bats | 2 +- .../bash/container/test-local/test-start.bats | 9 +- .../get-minikube-endpoints | 24 -- aladdin/bash_help.json | 10 +- aladdin/commands/build.py | 7 +- aladdin/commands/publish.py | 2 +- aladdin/commands/restart.py | 12 +- aladdin/commands/start.py | 10 - aladdin/lib/k8s/ingress.py | 4 + aladdin/lib/k8s/k3d.py | 7 + aladdin/lib/project_conf.py | 5 - .../{minikube => LOCAL}/config.json | 4 +- config-example/{minikube => LOCAL}/env.sh | 2 +- .../{minikube => LOCAL}/values.yaml | 2 +- docs/cluster_cmd.md | 18 +- docs/create_aladdin_configuration.md | 8 +- docs/deploy_cmd.md | 2 +- docs/publish_cmd.md | 2 +- docs/restart_cmd.md | 4 +- docs/start_cmd.md | 4 +- docs/troubleshooting.md | 5 +- pyproject.toml | 2 +- scripts/infra_k8s_check.sh | 200 ++--------------- scripts/install_nfs_mounts.sh | 41 ---- 32 files changed, 153 insertions(+), 594 deletions(-) delete mode 100755 aladdin/bash/container/get-dashboard-url/get-dashboard-url delete mode 100755 aladdin/bash/host/get-minikube-endpoints/get-minikube-endpoints create mode 100644 aladdin/lib/k8s/k3d.py rename config-example/{minikube => LOCAL}/config.json (62%) rename config-example/{minikube => LOCAL}/env.sh (95%) rename config-example/{minikube => LOCAL}/values.yaml (65%) delete mode 100755 scripts/install_nfs_mounts.sh diff --git a/Dockerfile b/Dockerfile index e132f19..7e76a44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,6 +67,9 @@ ARG ISTIO_VERSION=1.9.2 RUN curl -L https://istio.io/downloadIstio | ISTIO_VERSION="$ISTIO_VERSION" sh - && \ mv /istio-$ISTIO_VERSION/bin/istioctl /usr/local/bin/istioctl +ARG K3D_VERSION=4.4.4 +RUN curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | TAG=v$K3D_VERSION bash + # Install edgectl RUN curl -fL https://metriton.datawire.io/downloads/linux/edgectl -o /usr/local/bin/edgectl && \ chmod a+x /usr/local/bin/edgectl diff --git a/README.md b/README.md index 5fb3aaf..35314c3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## What is Aladdin? -Inspired by the Genie of the Lamp, Aladdin is a command line tool built by Fivestars to simplify kubernetes operations for clusters management and application development. We have done this by combining several command line tools including kops, minikube, docker, kubectl, helm, awscli, and git. +Inspired by the Genie of the Lamp, Aladdin is a command line tool built by Fivestars to simplify kubernetes operations for clusters management and application development. We have done this by combining several command line tools including kops, k3d, docker, kubectl, helm, awscli, and git. Use aladdin to: - Create and manage an aws kubernetes cluster @@ -17,9 +17,9 @@ The host component is responsible for: - Parsing command line options - Running any commands to be executed on the host machine - Checking and warning about any missing dependencies or installing the dependency in `~/.aladdin/bin` if possible -- Starting minikube +- Starting k3d (make sure your docker engine is running before running aladdin!) - Pulling the aladdin image -- Running the aladdin docker container (the container component) within minikube +- Running the aladdin docker container (the container component) The container component is responsible for - Running commands to manage your aws kubernetes cluster @@ -70,69 +70,11 @@ Then run: aladdin config set manage.software_dependencies false ``` -#### minikube -aladdin uses minikube to get access to docker functionality. -It also sets up minikube (file sharing etc) so that you can deploy to minikube. +#### k3d +aladdin uses k3d to support local development -But you may not need that if this applies to your situation: -1. You already have docker installed (say using docker.app on mac for example) -1. You are using an alternative to minikube (like docker-desktop or kind, etc) for local cluster or -1. You are using aladdin to connect to a remote cluster (like staging, prod etc) - -Then run: - -``` -aladdin config set manage.minikube false -``` - -### VM Configuration -Currently, the following parameters are configurable: - * memory: By default, we create a minikube vm with 4096MB (4GB) of memory. To change the size of the vm we create to e.g. 8GB, you may run: - ``` - aladdin config set minikube.memory 8192 - ``` - * vm\_driver: By default, we use the `virtualbox` virtualization backend. Currently, we support only this and the `none` backend, which runs containers directly on the underlying OS without virtualization (only supported on - linux). If your host is running linux, and you wish to use the 'none' backend (and avoid running in a VM), you may run, - ``` - aladdin config set minikube.vm_driver none - ``` - * disk\_size: The size of the VM disk, if applicable. Defaults to the minikube default (20000M, as of this writing). - ``` - aladdin config set minikube.disk_size 25000M - ``` - * cpus: The number of vCPUs to provision the VM with, if applicable. Defaults to the minikube default (2 as of this writing). - ``` - aladdin config set minikube.cpus 4 - ``` - -Note that these commands only take effect when the minikube cluster is first set up --- in order for them to take effect, you will need to first delete your existing minikube cluster (if present) and then (re-)run `aladdin --init`. - -### NFS mounts - -Aladdin uses minikube for local development which is a VirtualBox-based VM. Internally minikube mounts your `/Users` (or `/cygdrive/c/Users` for Cygwin users) directory to the root of the minikube filesystem. We have discovered that the `vboxsf` mounts are not as performant as NFS mounts and furthermore are not as reliable when it comes to detecting file changes made from the host. To address this, we replace the `vboxsf` mounts within minikube with NFS mounts. However, this requires a bit of manual setup on the host machine before it can be enabled. - -Once you have configured your host as an NFS server, instruct `aladdin` to replace the default `vboxsf` mounts with NFS mounts by setting this config value and then restarting your minikube instance: - -``` -aladdin config set nfs 1 -minikube stop -aladdin -``` - -#### NFS Host Setup - -1. Install an NFS service on your host - 1. **macOS** You should already have it available. - 1. **Windows** - We used to advise that one should install the `unfsd` package, but recent updates to that package have introduced seemingly insurmountable instabilities. We cannot recommend that one install `unfsd` for NFS capabilities. - There are other options such as [Allegro NFS](https://nfsforwindows.com/home) that have been shown to work, but setting that up is outside the scope of this documentation. -1. Add entries to your `/etc/exports` file - 1. **macOS** - ``` - echo "/Users -alldirs -mapall="$(id -u)":"$(id -g)" $(minikube ip)" | sudo tee -a /etc/exports - ``` - 1. **Windows** - *Possible, but unsupported* +### Local Cluster Resource Configuration +Currently, you can configure cpu, memory, and disk by going to your docker desktop UI, going to preferences, and then going to resources. The recommended configuration is 2 CPUs, 8GB memory, and 60GB disk. ## Creating and managing an aws kubernetes cluster This is all encapsulated in the [aladdin cluster command](./docs/cluster_cmd.md) @@ -166,7 +108,7 @@ We have several aladdin commands used for development and deployment. Note that - `cd {project repo name}` - `git checkout -b {feature branch}` - `aladdin build` -- `aladdin start --with-mount` +- `aladdin start` - do some development - commit code and push to remote - `aladdin publish` (publishes current hash, remember what that hash is) @@ -185,13 +127,12 @@ We have several aladdin commands used for development and deployment. Note that - `aladdin create-namespace` create the namespace you pass in. - `aladdin delete-namespace` delete the namespace you pass in _after_ removing all the helm packages on that namespace. - `aladdin get-dashboard-url` will output the url of your cluster's dashboard assuming it is installed. -- `aladdin get-minikube-endpoints` show endpoints for all minikube services, essentially wrapping `minikube service list`. -- `aladdin host` give instructions to update your local /etc/hosts file for minikube ingress compatibility. +- `aladdin host` give instructions to update your local /etc/hosts file for k3d ingress compatibility. - For a complete list of aladdin commands, run `aladdin -h`. ## Optional arguments to aladdin - `-h/--help` show help. -- `-c/--cluster` which cluster to connect to, defaults to `minikube`. +- `-c/--cluster` which cluster to connect to, defaults to `LOCAL`. - `-n/--namespace` which namespace to connect to, defaults to `default`. - `--init` force initialization logic (i.e. pull latest aladdin image, test aws config, initialize helm, etc...). This is forced every hour for each cluster/namespace combo. - `--dev` mount host's aladdin directory onto aladdin container. Useful when developing aladdin. @@ -207,18 +148,18 @@ $ aladdin bash Launching bash shell. Press CTRL+D to come back to this menu. This bash contain a lot of functions to help Don't forget to checkout scripts/bash_profile.bash in aladdin -minikube:default> build +LOCAL:default> build Building aladdin-demo docker image (~30 seconds) docker build -t aladdin-demo:local -f app/Dockerfile . Sending build context to Docker daemon 28.16kB . . . Successfully tagged aladdin-demo-commands:local -minikube:default> start --with-mount +LOCAL:default> start INFO:Found cluster values file . . . -minikube:default> refresh aladdin-demo-server +LOCAL:default> refresh aladdin-demo-server INFO:Refreshing deployment aladdin-demo-server -minikube:default> +LOCAL:default> ``` ## Tests @@ -278,7 +219,7 @@ Aladdin supports an ingress per namespace feature. This is off by default. We re "ingress_name": "ingress" } ``` -The "namespace_init" field tells aladdin to install the ingress-nginx project on namespace creation. This will be needed on remote clusters, but not on minikube, since we enable the ingress minikube addon. +The "namespace_init" field tells aladdin to install the ingress-nginx project on namespace creation. This will be needed on remote clusters, but not on LOCAL, since k3d comes with that out of the box. The "ingress_info" field tells aladdin how to sync your ingress. Services installed on a cluster with this feature will want to have their service type set to `NodePort` rather than `LoadBalancer`. This is most easily done by setting it in the values.yaml in your cluster's directory in aladdin config, i.e. adding this: ```yaml service: diff --git a/aladdin-container.sh b/aladdin-container.sh index 8496a4e..bfdae91 100755 --- a/aladdin-container.sh +++ b/aladdin-container.sh @@ -74,16 +74,6 @@ function exec_command_or_plugin() { echo "Error: unknown command $command for aladdin" } -function _replace_aws_secret() { - local creds username password server - creds=$(aws ecr get-login) - username=$(echo $creds | cut -d ' ' -f4) - password=$(echo $creds | cut -d ' ' -f6) - server=$(echo $creds | cut -d ' ' -f9) - kubectl delete secret aws || true - kubectl create secret docker-registry aws --docker-username="$username" --docker-password="$password" --docker-server="$server" --docker-email="can be anything" -} - function environment_init() { echo "START ENVIRONMENT CONFIGURATION=============================================" echo "CLUSTER_CODE = $CLUSTER_CODE" @@ -100,22 +90,19 @@ function environment_init() { if "$IS_LOCAL"; then mkdir -p $HOME/.kube/ - cp $HOME/.kube_local/config $HOME/.kube/config - # Replace e.g. /Users/ptr/.minikube with /root/.minikube in the minikube conf dir path - # (since that's where it will be mounted within the aladdin container) - sed 's|: \?.*\.minikube|: /root/.minikube| ; /: \/root\/.minikube/ s|\\|/|g' $HOME/.kube_local/config > $HOME/.kube/config + sed "s;https://0.0.0.0:$K3D_API_PORT;https://$HOST_ADDR:$K3D_API_PORT;g" $HOME/.kube_local/config > $HOME/.kube/config + kubectl config set-context "$NAMESPACE.k3d-$CLUSTER_NAME" --cluster "k3d-$CLUSTER_NAME" --namespace="$NAMESPACE" --user "admin@k3d-$CLUSTER_NAME" + kubectl config use-context "$NAMESPACE.k3d-$CLUSTER_NAME" else cp $HOME/.kube/config $HOME/.kube_local/$CLUSTER_NAME.config + kubectl config set-context "$NAMESPACE.$CLUSTER_NAME" --cluster "$CLUSTER_NAME" --namespace="$NAMESPACE" --user "$CLUSTER_NAME" + kubectl config use-context "$NAMESPACE.$CLUSTER_NAME" fi - kubectl config set-context "$NAMESPACE.$CLUSTER_NAME" --cluster "$CLUSTER_NAME" --namespace="$NAMESPACE" --user "$CLUSTER_NAME" - kubectl config use-context "$NAMESPACE.$CLUSTER_NAME" - _handle_authentication_config if $INIT; then - kubectl create namespace --cluster $CLUSTER_NAME $NAMESPACE || true - _replace_aws_secret || true + kubectl create namespace $NAMESPACE || true $PY_MAIN namespace-init --force fi fi diff --git a/aladdin.sh b/aladdin.sh index 85d6795..915dede 100755 --- a/aladdin.sh +++ b/aladdin.sh @@ -10,11 +10,10 @@ trap ctrl_trap INT # Set defaults on command line args DEV=false INIT=false -CLUSTER_CODE=minikube +CLUSTER_CODE=LOCAL NAMESPACE=default IS_TERMINAL=true SKIP_PROMPTS=false -MANAGE_MINIKUBE=true KUBERNETES_VERSION="1.19.7" MANAGE_SOFTWARE_DEPENDENCIES=true @@ -26,21 +25,8 @@ ALADDIN_PLUGIN_DIR= ALADDIN_BIN="$HOME/.aladdin/bin" PATH="$ALADDIN_BIN":"$PATH" -# Minikube defaults -DEFAULT_MINIKUBE_VM_DRIVER="virtualbox" -DEFAULT_MINIKUBE_MEMORY=4096 - source "$SCRIPT_DIR/shared.sh" # to load _extract_cluster_config_value -# If $MANAGE_MINIKUBE is true, then all commands will be executed -# using the external 'minikube' command. -# https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-command -# Otherwise calls to minikube will be no-op -function minikube() { - if "$MANAGE_MINIKUBE"; then - command minikube "$@" - fi -} function get_config_path() { if [[ ! -f "$HOME/.aladdin/config/config.json" ]]; then echo "Unable to find config directory. Please use 'aladdin config set config_dir ' to set config directory" @@ -63,15 +49,6 @@ function get_plugin_dir() { fi } -function get_manage_minikube() { - if [[ -f "$HOME/.aladdin/config/config.json" ]]; then - MANAGE_MINIKUBE=$(jq -r .manage.minikube $HOME/.aladdin/config/config.json) - if [[ "$MANAGE_MINIKUBE" == null ]]; then - MANAGE_MINIKUBE=true - fi - fi -} - function get_manage_software_dependencies() { if [[ -f "$HOME/.aladdin/config/config.json" ]]; then MANAGE_SOFTWARE_DEPENDENCIES=$(jq -r .manage.software_dependencies $HOME/.aladdin/config/config.json) @@ -88,6 +65,40 @@ function check_cluster_alias() { fi } +function get_config_variables() { + # Get host directory that will be mounted onto the docker container + if [[ -f "$HOME/.aladdin/config/config.json" ]]; then + HOST_DIR=$(jq -r .host_dir $HOME/.aladdin/config/config.json) + if [[ "$HOST_DIR" == null ]]; then + # defaults to osx + HOST_DIR="/Users" + fi + fi + # Get k3d service port + K3D_SERVICE_PORT=8081 # default value + if [[ -f "$HOME/.aladdin/config/config.json" ]]; then + K3D_SERVICE_PORT=$(jq -r .k3d.service_port $HOME/.aladdin/config/config.json) + if [[ "$K3D_SERVICE_PORT" == null ]]; then + K3D_SERVICE_PORT=8081 + fi + fi + # Get k3d api port + K3D_API_PORT=6550 # default value + if [[ -f "$HOME/.aladdin/config/config.json" ]]; then + K3D_API_PORT=$(jq -r .k3d.api_port $HOME/.aladdin/config/config.json) + if [[ "$K3D_API_PORT" == null ]]; then + K3D_API_PORT=6550 + fi + fi +} + +function get_host_addr() { + case "$OSTYPE" in + linux*) HOST_ADDR="172.17.0.1" ;; + *) HOST_ADDR="host.docker.internal" ;; + esac +} + function check_and_handle_init() { # Check if we need to force initialization local last_launched_file init_every current_time previous_run @@ -105,9 +116,7 @@ function check_and_handle_init() { if "$MANAGE_SOFTWARE_DEPENDENCIES"; then "$SCRIPT_DIR"/infra_k8s_check.sh --force fi - enter_minikube_env - copy_ssh_to_minikube - minikube addons enable ingress > /dev/null + check_or_start_k3d readonly repo_login_command="$(jq -r '.aladdin.repo_login_command' "$ALADDIN_CONFIG_FILE")" if [[ "$repo_login_command" != "null" ]]; then eval "$repo_login_command" @@ -121,112 +130,25 @@ function check_and_handle_init() { if "$MANAGE_SOFTWARE_DEPENDENCIES"; then "$SCRIPT_DIR"/infra_k8s_check.sh fi - enter_minikube_env - fi -} - -function set_minikube_config(){ - if "$MANAGE_MINIKUBE"; then - minikube config set kubernetes-version v$KUBERNETES_VERSION > /dev/null - - for key in vm_driver memory disk_size cpus; do - local minikube_key=$(tr _ - <<< "$key") # e.g., driver - local default_var="DEFAULT_MINIKUBE_$(tr a-z A-Z <<< "$key")" # e.g., DEFAULT_MINIKUBE_VM_DRIVER - - local value=$(aladdin config get "minikube.$key" "${!default_var:-}") - - if test -n "$value"; then - minikube config set "$minikube_key" "$value" > /dev/null - fi - done - fi -} - -function _start_minikube() { - if "$MANAGE_MINIKUBE"; then - local minikube_cmd="minikube start" - - if test "$OSTYPE" = "linux-gnu"; then - if test $(minikube config get driver) = "none"; then - # If we're running on native docker on a linux host, minikube start must happen as root - # due to limitations in minikube. Specifying CHANGE_MINIKUBE_NONE_USER causes minikube - # to switch users to $SUDO_USER (the user that called sudo) before writing out - # configuration. - minikube_cmd="sudo -E CHANGE_MINIKUBE_NONE_USER=true '$(which minikube)' start" - - else - # On linux, /home gets mounted on /hosthome in the minikube vm, so as not to - # override /home/docker. We still want the user's home directory to be in the - # same path both in and outside the minikube vm though, so symlink it into place. - minikube_cmd="$minikube_cmd &&\ - minikube ssh \"sudo mkdir '$HOME' && \ - sudo mount --bind '${HOME/\/home//hosthome}' '$HOME'\"" - fi - fi - - bash -c "$minikube_cmd" + check_or_start_k3d fi } -# Start minikube if we need to -function check_or_start_minikube() { - if "$MANAGE_MINIKUBE"; then - if ! minikube status | grep Running > /dev/null; then - - echo "Starting minikube... (this will take a moment)" - set_minikube_config - _start_minikube - - if test -n "$(aladdin config get nfs)"; then - if test "$(minikube config get driver)" != "none"; then - # Determine if we've installed our bootlocal.sh script to replace - # the default mounts with nfs mounts. - if ! minikube ssh -- "test -x /var/lib/boot2docker/bootlocal.sh"; then - echo "Installing NFS mounts from host..." - "$SCRIPT_DIR"/install_nfs_mounts.sh - echo "NFS mounts installed" - fi - fi - fi - echo "Minikube started" - else - if ! kubectl version | grep "Server" | grep "$KUBERNETES_VERSION" > /dev/null; then - echo "Minikube detected on the incorrect version, stopping and restarting" - minikube stop > /dev/null - minikube delete > /dev/null - set_minikube_config - check_or_start_minikube - fi - fi - fi +function _start_k3d() { + # start k3d cluster + k3d cluster create LOCAL --api-port "$K3D_API_PORT" -p "$K3D_SERVICE_PORT:80@loadbalancer" \ + --k3s-server-arg "--tls-san=$HOST_ADDR" --image "rancher/k3s:v$KUBERNETES_VERSION-k3s1" } -function copy_ssh_to_minikube() { - if "$MANAGE_MINIKUBE"; then - # Some systems fail when we directly mount the host's ~/.ssh directory into the aladdin container. - # This allows us to move the ~/.ssh directory into minikube and later mount that directory (with - # the adjusted ownernship and permissions) such that the container can leverage the user's - # credentials for ssh operations. - case "$OSTYPE" in - cygwin*) # Cygwin under windows - echo "Copying ~/.ssh into minikube" - ( - tmp_ssh_dir=".ssh.$(tr /dev/null - ;; - esac - : - fi -} - -function enter_minikube_env() { - if "$MANAGE_MINIKUBE"; then - if [[ $OSTYPE = darwin* || $OSTYPE = cygwin* || $OSTYPE = linux* ]]; then - check_or_start_minikube - eval "$(minikube docker-env)" +function check_or_start_k3d() { + if ! k3d cluster list | grep LOCAL > /dev/null; then + echo "Starting k3d LOCAL cluster... (this will take a moment)" + _start_k3d + else + if ! kubectl version | grep "Server" | grep "$KUBERNETES_VERSION" > /dev/null; then + echo "k3d detected on the incorrect version, stopping and restarting" + k3d cluster delete LOCAL > /dev/null + check_or_start_k3d fi fi } @@ -321,34 +243,16 @@ function prepare_docker_subcommands() { MOUNTS_CMD="$MOUNTS_CMD -v $(pathnorm "$ALADDIN_DIR")/aladdin-container.sh:/root/aladdin/aladdin-container.sh" fi - if "$IS_LOCAL"; then - if [ "$CLUSTER_CODE" = "minikube" ] ; then - MOUNTS_CMD="$MOUNTS_CMD -v $(pathnorm ~/.minikube):/root/.minikube" - fi - fi - if [[ -n "$ALADDIN_PLUGIN_DIR" ]]; then MOUNTS_CMD="$MOUNTS_CMD -v $(pathnorm $ALADDIN_PLUGIN_DIR):/root/aladdin-plugins" fi if "$DEV" || "$IS_LOCAL"; then - MOUNTS_CMD="$MOUNTS_CMD -v /:/aladdin_root" + MOUNTS_CMD="$MOUNTS_CMD -v $HOST_DIR:/aladdin_root$HOST_DIR" MOUNTS_CMD="$MOUNTS_CMD -w /aladdin_root$(pathnorm "$PWD")" fi } -function synchronize_datetime() -{ - if "$MANAGE_MINIKUBE"; then - # When minikube wakes up from sleep, date or time could be out of sync. - # Take date + time from host and set it on minikube. - if test "$(minikube config get vm-driver)" != "none"; then - echo "Synchronizing date and time on minikube with the host" - minikube ssh "sudo date -s @$(date +%s)" - fi - fi -} - function enter_docker_container() { if "$IS_PROD" && ! "$SKIP_PROMPTS"; then confirm_production @@ -374,11 +278,12 @@ function enter_docker_container() { -e "INIT=$INIT" \ -e "CLUSTER_CODE=$CLUSTER_CODE" \ -e "NAMESPACE=$NAMESPACE" \ - -e "MINIKUBE_IP=$(minikube ip)" \ -e "IS_LOCAL=$IS_LOCAL" \ -e "IS_PROD=$IS_PROD" \ -e "IS_TESTING=$IS_TESTING" \ -e "SKIP_PROMPTS=$SKIP_PROMPTS" \ + -e "K3D_API_PORT=$K3D_API_PORT" \ + -e "HOST_ADDR=$HOST_ADDR" \ -e "command=$command" \ `# Mount host credentials` \ `# Mount destination for aws creds will not be /root/.aws because we will possibly make` \ @@ -388,7 +293,6 @@ function enter_docker_container() { -v "$(pathnorm ~/.kube):/root/.kube_local" \ -v "$(pathnorm ~/.aladdin):/root/.aladdin" \ -v "$(pathnorm $ALADDIN_CONFIG_DIR):/root/aladdin-config" \ - `# Mount minikube parts` \ -v /var/run/docker.sock:/var/run/docker.sock \ `# Specific command` \ ${MOUNTS_CMD} \ @@ -436,13 +340,13 @@ done exec_host_command "$@" get_config_path get_plugin_dir -get_manage_minikube +get_host_addr get_manage_software_dependencies exec_host_plugin "$@" check_cluster_alias +get_config_variables check_and_handle_init set_cluster_helper_vars handle_ostypes prepare_docker_subcommands -synchronize_datetime enter_docker_container "$@" diff --git a/aladdin/bash/container/cluster/cluster b/aladdin/bash/container/cluster/cluster index d858115..90fb7ff 100755 --- a/aladdin/bash/container/cluster/cluster +++ b/aladdin/bash/container/cluster/cluster @@ -29,7 +29,7 @@ function usage { optional arguments: -h, --help show this help message and exit --cluster CLUSTER, -c CLUSTER - cluster dns, defaults to minikube current : [minikube] + cluster dns, defaults to LOCAL current : [$CLUSTER_NAME] --namespace NAMESPACE, -n NAMESPACE namespace name, defaults to default current : [default] --init force the initialization steps (dl latest docker, aws auth, etc...) diff --git a/aladdin/bash/container/get-dashboard-url/get-dashboard-url b/aladdin/bash/container/get-dashboard-url/get-dashboard-url deleted file mode 100755 index b40f7a1..0000000 --- a/aladdin/bash/container/get-dashboard-url/get-dashboard-url +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -set -eu -o pipefail - -function get_dashboard_url { - if [[ $CLUSTER_CODE == "minikube" ]]; then - echo "Please run \"minikube dashboard\" which will launch the minikube dashboard in a browser" - else - user="admin" - passwd=$(kops get secrets kube --type secret -oplaintext | tr -d ' ') - base=$(kubectl cluster-info | grep "Kubernetes master" | cut -d '/' -f3)/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy/#!/workload?namespace=$NAMESPACE - echo https://$user:$passwd@$base - fi -} - -function usage { - cat <<-EOF - usage: aladdin get-dashboard-url [-h] - - optional arguments: - -h, --help show this help message and exit - EOF -} - -if [[ $# -eq 0 ]]; then - get_dashboard_url -elif [[ "$1" == "-h" || "$1" == "--help" ]]; then - usage -else - echo >&2 "aladdin: error: unrecognized arguments: $1" - exit 1 -fi diff --git a/aladdin/bash/container/host/host b/aladdin/bash/container/host/host index 0dbcf17..d17a95b 100755 --- a/aladdin/bash/container/host/host +++ b/aladdin/bash/container/host/host @@ -10,9 +10,8 @@ function host { # On mac/linux : # - sudo vim /etc/hosts # and add this: - $MINIKUBE_IP minikube EOF - kubectl get ingress ingress -o=json 2>/dev/null | jq '.spec.rules[]?.host' --raw-output | grep -v '^$' | xargs -I % echo "$MINIKUBE_IP %" + kubectl get ingress ingress -o=json 2>/dev/null | jq '.spec.rules[]?.host' --raw-output | grep -v '^$' | xargs -I % echo "127.0.0.1 %" } function usage { diff --git a/aladdin/bash/container/test-local/test-local b/aladdin/bash/container/test-local/test-local index 6478c57..ea86813 100755 --- a/aladdin/bash/container/test-local/test-local +++ b/aladdin/bash/container/test-local/test-local @@ -38,7 +38,7 @@ if [[ $# -eq 0 ]]; then if $IS_LOCAL && $IS_TESTING; then test_local else - echo >&2 "aladdin test-local should only be called on a local testing minikube cluster" + echo >&2 "aladdin test-local should only be called on a local testing k3d cluster" fi elif [[ "$1" == "-h" || "$1" == "--help" ]]; then usage diff --git a/aladdin/bash/container/test-local/test-refresh.bats b/aladdin/bash/container/test-local/test-refresh.bats index 0d90ee8..34bf9b5 100644 --- a/aladdin/bash/container/test-local/test-refresh.bats +++ b/aladdin/bash/container/test-local/test-refresh.bats @@ -6,5 +6,5 @@ set -o pipefail $PY_MAIN refresh aladdin-test-server node_port=$(kubectl get svc aladdin-test-server -o json | jq -r '.spec.ports[] | select (.name == "http").nodePort') sleep 60 - [ $(curl "$MINIKUBE_IP:$node_port/ping") == "aladdin-test-message2" ] + [ $(curl "127.0.0.1:$node_port/ping") == "aladdin-test-message2" ] } diff --git a/aladdin/bash/container/test-local/test-start.bats b/aladdin/bash/container/test-local/test-start.bats index d1c159c..85ff6bb 100644 --- a/aladdin/bash/container/test-local/test-start.bats +++ b/aladdin/bash/container/test-local/test-start.bats @@ -16,9 +16,9 @@ set -o pipefail kubectl get hpa | grep "aladdin-test-hpa\s" } -@test "Test aladdin start --with-mount command" { - # Call aladdin start --with-mount - $PY_MAIN start --with-mount +@test "Test aladdin start command" { + # Call aladdin start + $PY_MAIN start # Check helm release is present helm list | grep "aladdin-test-default\s" # Check kubernetes resources are present @@ -29,7 +29,4 @@ set -o pipefail kubectl get cm | grep "aladdin-test-nginx\s" kubectl get cm | grep "aladdin-test-uwsgi\s" kubectl get hpa | grep "aladdin-test-hpa\s" - # Check mount resources are present - kubectl get pv | grep "aladdin-test-nfs-volume\s" - kubectl get pvc | grep "aladdin-test-nfs-volume-claim\s" } diff --git a/aladdin/bash/host/get-minikube-endpoints/get-minikube-endpoints b/aladdin/bash/host/get-minikube-endpoints/get-minikube-endpoints deleted file mode 100755 index db4192b..0000000 --- a/aladdin/bash/host/get-minikube-endpoints/get-minikube-endpoints +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -set -eu -o pipefail - -function get_minikube_endpoints() { - minikube service list -} - -function usage { - cat <<-EOF - usage: aladdin get-minikube-endpoints [-h] - - optional arguments: - -h, --help show this help message and exit - EOF -} - -if [[ $# -eq 0 ]]; then - get_minikube_endpoints -elif [[ "$1" == "-h" ]]; then - usage -else - echo >&2 "aladdin: error: unrecognized arguments: $1" - exit 1 -fi diff --git a/aladdin/bash_help.json b/aladdin/bash_help.json index 649e6e9..a03bbff 100644 --- a/aladdin/bash_help.json +++ b/aladdin/bash_help.json @@ -26,17 +26,11 @@ "env": { "help": "Set aladdin env variables : $(aladdin env)" }, - "get-minikube-endpoints": { - "help": "Show endpoints for all minikube services" - }, - "get-dashboard-url": { - "help": "Show url for cluster dashboard" - }, "helm-history": { "help": "Show the history of a helm release" }, "host": { - "help": "Give instructions to update local /etc/hosts file for minikube ingress compatibility" + "help": "Give instructions to update local /etc/hosts file for k3d ingress compatibility" }, "load-images": { "help": "Import local images" @@ -45,7 +39,7 @@ "help": "Export images locally" }, "test-local": { - "help": "Test aladdin local commands using a test minikube cluster" + "help": "Test aladdin local commands using a test k3d cluster" }, "test-remote": { "help": "Test aladdin remote commands on a remote test cluster" diff --git a/aladdin/commands/build.py b/aladdin/commands/build.py index b1abad0..7f9ccf1 100644 --- a/aladdin/commands/build.py +++ b/aladdin/commands/build.py @@ -2,6 +2,7 @@ from aladdin.lib.project_conf import ProjectConf from aladdin.lib.arg_tools import container_command +from aladdin.lib.k8s.k3d import K3d def parse_args(sub_parser): @@ -18,5 +19,9 @@ def build_args(args): @container_command def build(build_args): + tag = "local" + k3d = K3d() pc = ProjectConf() - pc.build_docker(env={"HASH": "local"}, build_args=build_args) + pc.build_docker(env={"HASH": tag}, build_args=build_args) + images = pc.get_docker_images() + k3d.import_images([f"{image}:{tag}" for image in images]) diff --git a/aladdin/commands/publish.py b/aladdin/commands/publish.py index ced2686..ce3661f 100644 --- a/aladdin/commands/publish.py +++ b/aladdin/commands/publish.py @@ -22,7 +22,7 @@ def parse_args(sub_parser): exclude_steps_group.add_argument( "--build-only", action="store_true", - help="only builds docker images in your minikube env with hash and timestamp as tags", + help="only builds docker images in your LOCAL env with hash as tag", ) exclude_steps_group.add_argument( "--build-publish-ecr-only", diff --git a/aladdin/commands/restart.py b/aladdin/commands/restart.py index 9d2afa4..8d449ad 100644 --- a/aladdin/commands/restart.py +++ b/aladdin/commands/restart.py @@ -12,19 +12,13 @@ def parse_args(sub_parser): dest="charts", help="Start only these charts (may be specified multiple times)", ) - subparser.add_argument( - "--with-mount", - "-m", - action="store_true", - help="Mount user's host's project repo onto container", - ) def restart_args(args): - restart(args.namespace, args.charts, args.with_mount) + restart(args.namespace, args.charts) @container_command -def restart(namespace, charts, with_mount): +def restart(namespace, charts): stop.stop(namespace, charts) - start.start(namespace, charts, False, with_mount) + start.start(namespace, charts, False) diff --git a/aladdin/commands/start.py b/aladdin/commands/start.py index 04e4afb..304f811 100644 --- a/aladdin/commands/start.py +++ b/aladdin/commands/start.py @@ -25,12 +25,6 @@ def parse_args(sub_parser): action="store_true", help="Run the helm as test and don't actually run it", ) - subparser.add_argument( - "--with-mount", - "-m", - action="store_true", - help="Mount user's host's project repo onto container", - ) subparser.add_argument( "--force-helm", action="store_true", @@ -49,7 +43,6 @@ def start_args(args): args.namespace, args.charts, args.dry_run, - args.with_mount, args.force_helm, args.set_override_values, ) @@ -60,7 +53,6 @@ def start( namespace, charts=None, dry_run=False, - with_mount=False, force_helm=False, set_override_values=None, ): @@ -79,9 +71,7 @@ def start( # Start command values values = { "deploy.imageTag": "local", - "deploy.mountPath": pc.mount_path, "deploy.namespace": namespace, - "deploy.withMount": with_mount, "project.name": pc.name, "service.certificateArn": cr.service_certificate_arn, "service.certificateScope": cr.service_certificate_scope, diff --git a/aladdin/lib/k8s/ingress.py b/aladdin/lib/k8s/ingress.py index 54c6e84..a7fcb98 100644 --- a/aladdin/lib/k8s/ingress.py +++ b/aladdin/lib/k8s/ingress.py @@ -34,6 +34,10 @@ def build_ingress(services, dns_suffix, dual_dns_prefix_annotation_name, ingress ingress.spec = client.NetworkingV1beta1IngressSpec() ingress.spec.rules = [] service_tuples = _create_ingress_service_tuples(services, dual_dns_prefix_annotation_name) + # A little bit of a hack to have the ingress put the port:443 entries before the port:80 entries, + # so that the port:80 entries take precedence if the service name is the same. Without this + # we get ssl errors when accessing services behind the ingress locally because of k3d internals + service_tuples = sorted(service_tuples, key = lambda x: x[1], reverse=True) for dns_prefix, port, service in service_tuples: ingress_rule = client.NetworkingV1beta1IngressRule() ingress_rule.host = "%s.%s" % (dns_prefix, dns_suffix) diff --git a/aladdin/lib/k8s/k3d.py b/aladdin/lib/k8s/k3d.py new file mode 100644 index 0000000..92a358a --- /dev/null +++ b/aladdin/lib/k8s/k3d.py @@ -0,0 +1,7 @@ +import subprocess +import os + +class K3d: + + def import_images(self, images): + subprocess.check_call(["k3d", "image", "import", "-c", os.environ["CLUSTER_CODE"], *images]) diff --git a/aladdin/lib/project_conf.py b/aladdin/lib/project_conf.py index 7b098db..00e2c3a 100644 --- a/aladdin/lib/project_conf.py +++ b/aladdin/lib/project_conf.py @@ -57,11 +57,6 @@ def __init__(self, path="."): def name(self): return self.lamp_content["name"] - @property - def mount_path(self): - # Under aladdin, we are using /minikube_root , but under minikube it's / - return re.sub(r"^/aladdin_root", "", self.path) - @property def build_command(self): cmd = search("build_docker", self.lamp_content) or ["aladdin", "build-components"] diff --git a/config-example/minikube/config.json b/config-example/LOCAL/config.json similarity index 62% rename from config-example/minikube/config.json rename to config-example/LOCAL/config.json index bc38965..b229219 100644 --- a/config-example/minikube/config.json +++ b/config-example/LOCAL/config.json @@ -1,7 +1,7 @@ { "is_local": true, - "cluster_name": "minikube", - "root_dns": "minikube", + "cluster_name": "LOCAL", + "root_dns": "LOCAL", "allowed_namespaces": [ "*" ], diff --git a/config-example/minikube/env.sh b/config-example/LOCAL/env.sh similarity index 95% rename from config-example/minikube/env.sh rename to config-example/LOCAL/env.sh index 3b4b4d9..c969710 100644 --- a/config-example/minikube/env.sh +++ b/config-example/LOCAL/env.sh @@ -13,7 +13,7 @@ export NODE_COUNT= # aws ec2 describe-availability-zones export ZONES= -export DNS_ZONE=minikube +export DNS_ZONE=LOCAL export CLUSTER_NAME=$DNS_ZONE export KOPS_STATE_STORE=s3://$DNS_ZONE diff --git a/config-example/minikube/values.yaml b/config-example/LOCAL/values.yaml similarity index 65% rename from config-example/minikube/values.yaml rename to config-example/LOCAL/values.yaml index 326adb7..083df33 100644 --- a/config-example/minikube/values.yaml +++ b/config-example/LOCAL/values.yaml @@ -1,6 +1,6 @@ service: publicServiceType: "NodePort" - certificateArn: "no-certificate-on-minikube" + certificateArn: "no-certificate-on-local" deploy: ecr: diff --git a/docs/cluster_cmd.md b/docs/cluster_cmd.md index d2c00cf..a3c3a79 100644 --- a/docs/cluster_cmd.md +++ b/docs/cluster_cmd.md @@ -46,14 +46,14 @@ Manage kubernetes clusters positional arguments: {backup,create-at-aws,create-config,delete,export-config,import-config,init,populate,rolling-update-at-aws,update-at-aws,view-config} cluster subcommands - backup export all k8s resources for each namespace to minikube/.yaml for later repopulation - create-at-aws create cluster minikube from kops configuration - create-config import kops configuration for cluster minikube based on minikube environment file - delete delete cluster minikube - export-config export kops configuration for cluster minikube to host machine - import-config update kops cluster minikube state with host machine cluster files - init deploy all cluster_init projects as specified by your minikube config.json file - populate populate a cluster using the minikube/.yaml files generated from cluster backup + backup export all k8s resources for each namespace to $CLUSTER_NAME/.yaml for later repopulation + create-at-aws create cluster $CLUSTER_NAME from kops configuration + create-config import kops configuration for cluster $CLUSTER_NAME based on $CLUSTER_NAME environment file + delete delete cluster $CLUSTER_NAME + export-config export kops configuration for cluster $CLUSTER_NAME to host machine + import-config update kops cluster $CLUSTER_NAME state with host machine cluster files + init deploy all cluster_init projects as specified by your $CLUSTER_NAME config.json file + populate populate a cluster using the $CLUSTER_NAME/.yaml files generated from cluster backup rolling-update-at-aws update cluster configuration by restarting cluster nodes update-at-aws update cluster configuration without restarting cluster nodes @@ -62,7 +62,7 @@ positional arguments: optional arguments: -h, --help show this help message and exit --cluster CLUSTER, -c CLUSTER - cluster dns, defaults to minikube current : [minikube] + cluster dns, defaults to LOCAL current : [$CLUSTER_NAME] --namespace NAMESPACE, -n NAMESPACE namespace name, defaults to default current : [default] --init force the initialization steps (dl latest docker, aws auth, etc...) diff --git a/docs/create_aladdin_configuration.md b/docs/create_aladdin_configuration.md index 76f8205..7986280 100644 --- a/docs/create_aladdin_configuration.md +++ b/docs/create_aladdin_configuration.md @@ -7,7 +7,7 @@ aladdin-config/ config.json default/ config.json - minikube/ + LOCAL/ config.json env.sh REMOTE-CLUSTER-1/ @@ -98,7 +98,7 @@ export ADMIN_ACCESS= export IMAGE= ``` -Most these variables are just used by kops when creating the cluster, which is wrapped by aladdin. If you need more info, check [here](https://github.com/kubernetes/kops/blob/master/docs/cli/kops_create_cluster.md). Note that the env.sh in your minikube folder will be mostly empty since you are not actually creating a cluster in that scenario. +Most these variables are just used by kops when creating the cluster, which is wrapped by aladdin. If you need more info, check [here](https://github.com/kubernetes/kops/blob/master/docs/cli/kops_create_cluster.md). Note that the env.sh in your LOCAL folder will be mostly empty since you are not actually creating a cluster in that scenario. ## Cluster config.json file The config.json file in each of your subdirectories in your config folder will contain cluster-specific configuration for your aladdin installation. Here is an example config.json file for a specific cluster: @@ -133,12 +133,12 @@ Note: Aladdin also supports a `default/` folder which can have a `config.json` f Note: Aladdin allows you to override configuration on a namespace level as well. To do this, create a namespace-overrides folder in your cluster subdirectory folder, and create a folder for each namespace you want to override config for. Then create a `config.json` file with any overrides. See the `config-example/CLUSTERDEV/namespace-overrides/test/config.json` file for an example. ## Cluster values.yaml file -The values.yaml file in each of your subdirectories in your config folder will contain cluster-specific values which will be set for all helm charts in this cluster when running `aladdin deploy` or `aladdin start`. Here is an example values.yaml file for a minikube cluster: +The values.yaml file in each of your subdirectories in your config folder will contain cluster-specific values which will be set for all helm charts in this cluster when running `aladdin deploy` or `aladdin start`. Here is an example values.yaml file for a LOCAL cluster: ```yaml service: publicServiceType: "NodePort" - certificateArn: "no-certificate-on-minikube" + certificateArn: "no-certificate-on-local" deploy: ecr: diff --git a/docs/deploy_cmd.md b/docs/deploy_cmd.md index 852a620..ae01a6f 100755 --- a/docs/deploy_cmd.md +++ b/docs/deploy_cmd.md @@ -35,7 +35,7 @@ optional arguments: - Example: `aladdin -c DEV -n test deploy aladdin-demo 5a5e59b2f6 --set-override-values replicas=3 resources.cpu.request.enable=true` - Example: `aladdin -c DEV -n special deploy aladdin-demo 5a5e59b2f6 --chart aladdin-demo-special` -Note: Although this command is primarily used for non local environments, you can still use it in minikube rather than using `aladdin start`. The benefit of this is that you are not required to have the project pulled locally. The cons of this is that you have to get the githash you want to deploy, and you cannot mount your host code in this method. +Note: Although this command is primarily used for non local environments, you can still use it in LOCAL rather than using `aladdin start`. The benefit of this is that you are not required to have the project pulled locally. The cons of this is that you have to get the githash you want to deploy, and you cannot mount your host code in this method. Also note: Aladdin deploy will also request a certificate arn for `*.{namespace}.{cluster dns}` or `*.{service_dns_suffix}` if you have supplied `service_dns_suffix` in your config. It will use helm to pass in `--set service.certificateArn={certificate arn}` once the certificate is issued. Since the certificate validation happens asynchronously, it may not be applied the first time you deploy. However, once it is issued, if you have these lines in your k8s service yaml file: ``` diff --git a/docs/publish_cmd.md b/docs/publish_cmd.md index a1580fe..6af2e9a 100755 --- a/docs/publish_cmd.md +++ b/docs/publish_cmd.md @@ -13,7 +13,7 @@ usage: aladdin publish [-h] optional arguments: -h, --help show this help message and exit - --build-only only builds docker images in your minikube env with + --build-only only builds docker images in your LOCAL env with hash and timestamp as tags --build-publish-ecr-only only build and publish docker images to ecr diff --git a/docs/restart_cmd.md b/docs/restart_cmd.md index 8b0a117..4edac0a 100755 --- a/docs/restart_cmd.md +++ b/docs/restart_cmd.md @@ -1,7 +1,7 @@ # Aladdin Restart Restart is one of aladdin's commands used for local development. This command is to be called from within an aladdin-compatible project repo. This command removes a project from your local environment, and then installs it back. ``` -usage: aladdin restart [-h] [--namespace NAMESPACE] [--with-mount] [--chart CHART_NAME]... +usage: aladdin restart [-h] [--namespace NAMESPACE] [--chart CHART_NAME]... optional arguments: -h, --help show this help message and exit @@ -9,9 +9,7 @@ optional arguments: namespace name, defaults to default current : [default] --chart CHART_NAME Restart only these charts (can be specified multiple times) - --with-mount, -m Mount user's host's project repo onto container ``` -Note that for `--with-mount` to work as expected, you will have to set up the necessary volume and volumeMounts as described in the aladdin demo project [here](https://github.com/fivestars-os/aladdin-demo/blob/master/docs/code_mounting.md). If the `--chart` option is not provided, all charts defined in the `lamp.json` file will be restarted. diff --git a/docs/start_cmd.md b/docs/start_cmd.md index 8657e10..17e999a 100755 --- a/docs/start_cmd.md +++ b/docs/start_cmd.md @@ -1,7 +1,7 @@ # Aladdin Start Start is one of aladdin's commands used for local development. This command is to be called from within an aladdin-compatible project repo. This command installs a project to your local environment. ``` -usage: aladdin start [-h] [--namespace NAMESPACE] [--dry-run] [--with-mount] +usage: aladdin start [-h] [--namespace NAMESPACE] [--dry-run] [--chart CHART_NAME]... [--force-helm] [--set-override-values SET_OVERRIDE_VALUES [SET_OVERRIDE_VALUES ...]] @@ -12,7 +12,6 @@ optional arguments: namespace name, defaults to default current : [default] --dry-run, -d Run the helm as test and don't actually run it - --with-mount, -m Mount user's host's project repo onto container --chart CHART_NAME Start only these charts (can be specified multiple times) --force-helm Have helm force resource update through delete/recreate if needed @@ -20,6 +19,5 @@ optional arguments: override values in the values file. Syntax: --set key1=value1 key2=value2 ... ``` -Note that for `--with-mount` to work as expected, you will have to set up the necessary volume and volumeMounts as described in the aladdin demo project [here](https://github.com/fivestars-os/aladdin-demo/blob/master/docs/code_mounting.md). If the `--chart` option is not provided, all charts defined in the `lamp.json` file will be started. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 9ccfa22..2bd32c1 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -1,11 +1,10 @@ # Troubleshooting You may want to first try: - Rerunning your aladdin command with `--init` flag -- Restarting minikube via `minikube stop && minikube start` and then rerunning your command -- Restarting minikube via `minikube delete && minikube start` and then rerunning your command (You will lose your local images and need to rebuild in this scenario) +- Restarting your LOCAL cluster via `k3d cluster delete LOCAL && aladdin --init` and then rerunning your command ## Specific Issues ### InvalidSignatureException -Fix this by restarting minikube via `minikube stop && minikube start` and then rerunning your command +Fix this by restarting your LOCAL cluster via `k3d cluster delete LOCAL && aladdin --init` and then rerunning your command ### Problems with git processing during aladdin deploy or publish If your error is something like this: ``` diff --git a/pyproject.toml b/pyproject.toml index 95121d5..0910283 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aladdin" -version = "1.19.7.4" +version = "1.19.7.6" description = "" authors = ["Fivestars "] include = [ diff --git a/scripts/infra_k8s_check.sh b/scripts/infra_k8s_check.sh index 8b821ff..3b0670a 100755 --- a/scripts/infra_k8s_check.sh +++ b/scripts/infra_k8s_check.sh @@ -6,34 +6,21 @@ set -eu -o pipefail # The minimum dependency for windows is cygwin with wget. # No minimum dependency found for mac -# There is a problem with virtualbox that doesn't mount the right path. -# To correct it, set the mounted volume as "c:/Users" => "/c/Users" and this should correct it. -# After setting that, you have to restart the minikube : minikube stop && minikube start - # To force the script to do the full check, use the parameter '--force' - -#- from : https://github.com/kubernetes/minikube/releases -VERSION_MINIKUBE="1.17.1" -#- from : https://github.com/docker/docker-ce/releases -VERSION_DOCKER="20.10.2" +#- from : https://github.com/rancher/k3d/releases +VERSION_K3D="4.4.4" #- from : https://github.com/kubernetes/kubernetes/releases VERSION_KUBECTL="1.19.7" #- from : https://github.com/kubernetes/helm/releases VERSION_HELM="3.5.2" -FULL_VERSION_VIRTUALBOX="6.0.14r133895" - -VERSION_VIRTUALBOX="$(echo "$FULL_VERSION_VIRTUALBOX" | cut -dr -f1)" -VERSION_R_VIRTUALBOX="$(echo "$FULL_VERSION_VIRTUALBOX" | cut -dr -f2-)" # This script is meant to check and test the necessary tools for using the infra tools. # -# To run minikube : -# - minikube +# To run k3d : +# - k3d # - kubectl -# - docker client -# - virtualbox # - helm # To launch the bash script @@ -308,52 +295,23 @@ function install_wget_mac(){ eval $install_cmd wget >/dev/null 2>/dev/null ; } function install_wget_ubuntu(){ eval $install_cmd wget >/dev/null 2>/dev/null ; } -function check_minikube(){ version "$ALADDIN_BIN/minikube version" "$VERSION_MINIKUBE" ;} +function check_k3d(){ version "$ALADDIN_BIN/k3d version" "$VERSION_K3D" ;} -function install_minikube_win(){ - typeset url="https://storage.googleapis.com/minikube/releases/v${VERSION_MINIKUBE}/minikube-windows-amd64.exe" - install_url_exe "minikube.exe" "$url" -} -function install_minikube_mac(){ - typeset url="https://storage.googleapis.com/minikube/releases/v${VERSION_MINIKUBE}/minikube-darwin-amd64" - install_url_cmd "minikube" "$url" +function install_k3d() { + curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | K3D_INSTALL_DIR=$ALADDIN_BIN TAG=v${VERSION_K3D} USE_SUDO=false bash } -function install_minikube_alpine(){ - typeset url="https://storage.googleapis.com/minikube/releases/v${VERSION_MINIKUBE}/minikube-linux-amd64" -# install_url_cmd "minikube" "$url" -# do not install minikube on alpine, it does not work -} -function install_minikube_ubuntu(){ - typeset url="https://storage.googleapis.com/minikube/releases/v${VERSION_MINIKUBE}/minikube-linux-amd64" - install_url_cmd "minikube" "$url" -} - -function check_docker(){ - case "$OSTYPE" in - cygwin) - has_prog docker; - ;; - *) - version "$ALADDIN_BIN/docker --version" "$VERSION_DOCKER" ; - ;; - esac +function install_k3d_win(){ + install_k3d } -function install_docker_win(){ - typeset url="https://download.docker.com/win/static/stable/x86_64/docker-${VERSION_DOCKER}.zip" - install_url_zip "docker.exe" "docker/docker.exe" "$url" +function install_k3d_mac(){ + install_k3d } -function install_docker_mac(){ - typeset url="https://download.docker.com/mac/static/stable/x86_64/docker-${VERSION_DOCKER}.tgz" - install_url_tgz "docker" "docker/docker" "$url" +function install_k3d_alpine(){ + install_k3d } -function install_docker_alpine(){ - typeset url="https://download.docker.com/linux/static/stable/x86_64/docker-${VERSION_DOCKER}.tgz" - install_url_tgz "docker" "docker/docker" "$url" -} -function install_docker_ubuntu(){ - typeset url="https://download.docker.com/linux/static/stable/x86_64/docker-${VERSION_DOCKER}.tgz" - install_url_tgz "docker" "docker/docker" "$url" +function install_k3d_ubuntu(){ + install_k3d } function check_kubectl(){ version "$ALADDIN_BIN/kubectl version --client" "Client.*v$VERSION_KUBECTL" ; } @@ -393,113 +351,6 @@ function install_helm_ubuntu(){ install_url_tgz "helm" "linux-amd64/helm" "$url" } - -function install_virtualbox_win(){ - #http://download.virtualbox.org/virtualbox/5.1.18/VirtualBox-5.1.18-114002-Win.exe - - typeset url="http://download.virtualbox.org/virtualbox/$VERSION_VIRTUALBOX/VirtualBox-$VERSION_VIRTUALBOX-$VERSION_R_VIRTUALBOX-Win.exe" - typeset file_path="$(tmp_dir)/virtual-box-install.exe" - - # Just make sure minikube is stopped if already exists - minikube stop >/dev/null 2>/dev/null - - WGET "$url" "$file_path" - chmod a+x "$file_path" ; cygstart --action=runas "$file_path" # run the virtualbox as admin - # Wait for the installation to be done - while ! check_virtualbox ; do - sleep 10 - done - clean_tmp_dir - - echo "Installing extetion" - install_virtualbox_extension_win -} - -function install_virtualbox_mac(){ - # Just make sure minikube is stopped if already exists - minikube stop >/dev/null 2>/dev/null - typeset root_file_name="VirtualBox-${VERSION_VIRTUALBOX}-${VERSION_R_VIRTUALBOX}-OSX" - - typeset url="http://download.virtualbox.org/virtualbox/$VERSION_VIRTUALBOX/$root_file_name.dmg" - typeset v_path="$HOME/Downloads/$root_file_name.dmg" - WGET "$url" "$v_path" - hdiutil attach "$v_path" >/dev/null - # Now it's going to ask for the sudo password - alias CAN_IN_RUN_SUDO="sudo -n uptime 2>&1 | grep load" - if ! sudo -n uptime 2>&1 | grep load >/dev/null ; then - printf '\n sudo ' - fi - sudo installer -package /Volumes/VirtualBox/VirtualBox.pkg -target / - while ! check_virtualbox ; do - sleep 10 - done - hdiutil detach "/Volumes/VirtualBox" >/dev/null - clean_tmp_dir - - install_virtualbox_extension_mac -} - -function install_virtualbox_alpine(){ - # Just make sure minikube is stopped if already exists - minikube stop >/dev/null 2>/dev/null - typeset root_file_name="VirtualBox-${VERSION_VIRTUALBOX}-${VERSION_R_VIRTUALBOX}-Linux_amd64.run" - typeset url="http://download.virtualbox.org/virtualbox/$VERSION_VIRTUALBOX/$root_file_name" - typeset v_path="$(tmp_dir)/$root_file_name" - echo "Downloading to $v_path" - WGET "$url" "$v_path" - chmod +x ${v_path} - # Now it's going to ask for the sudo password - if ! sudo -n uptime 2>&1 | grep load >/dev/null ; then - printf '\n sudo ' - fi - sudo ${v_path} install >/dev/null - - clean_tmp_dir - - install_virtualbox_extension_mac -} -function install_virtualbox_ubuntu(){ - # Just make sure minikube is stopped if already exists - minikube stop >/dev/null 2>/dev/null - typeset root_file_name="VirtualBox-${VERSION_VIRTUALBOX}-${VERSION_R_VIRTUALBOX}-Linux_amd64.run" - typeset url="http://download.virtualbox.org/virtualbox/$VERSION_VIRTUALBOX/$root_file_name" - typeset v_path="$(tmp_dir)/$root_file_name" - echo "Downloading to $v_path" - WGET "$url" "$v_path" - chmod +x ${v_path} - # Now it's going to ask for the sudo password - if ! sudo -n uptime 2>&1 | grep load >/dev/null ; then - printf '\n sudo ' - fi - sudo ${v_path} install >/dev/null - - clean_tmp_dir - - install_virtualbox_extension_mac -} - -function install_virtualbox_extension_win(){ - typeset file_name="Oracle_VM_VirtualBox_Extension_Pack-$VERSION_VIRTUALBOX-$VERSION_R_VIRTUALBOX.vbox-extpack" - typeset url="http://download.virtualbox.org/virtualbox/${VERSION_VIRTUALBOX}/$file_name" - typeset file_path="$(tmp_dir)/$file_name" - - WGET "$url" "$file_path" - VBoxManage extpack install "$(cygpath -w "$file_path")" --replace - clean_tmp_dir -} - -function install_virtualbox_extension_mac(){ - typeset file_name="Oracle_VM_VirtualBox_Extension_Pack-$VERSION_VIRTUALBOX-$VERSION_R_VIRTUALBOX.vbox-extpack" - typeset url="http://download.virtualbox.org/virtualbox/${VERSION_VIRTUALBOX}/$file_name" - typeset file_path="$(tmp_dir)/$file_name" - - WGET "$url" "$file_path" - VBoxManage extpack install "$file_path" --replace - clean_tmp_dir -} - -function check_virtualbox(){ has_prog vboxmanage ; } - function install_jq_win(){ eval $install_cmd jq >/dev/null 2>/dev/null ; } function install_jq_mac(){ eval $install_cmd jq >/dev/null 2>/dev/null ; } function install_jq_alpine(){ eval $install_cmd jq >/dev/null 2>/dev/null ; } @@ -547,13 +398,10 @@ function main(){ win) check_and_warn "apt-cyg " aptcyg check_and_warn "unzip " unzip - check_and_warn "wget " wget - check_and_install "minikube ($VERSION_MINIKUBE) " minikube - check_and_warn "docker ($VERSION_DOCKER)" docker + check_and_install "k3d ($VERSION_K3D) " k3d check_and_install "kubectl ($VERSION_KUBECTL) " kubectl check_and_install "helm ($VERSION_HELM) " helm - check_and_warn "virtualbox " virtualbox check_and_warn "jq " jq #check_and_warn "git " git check_and_warn "python3 " python3 @@ -566,11 +414,9 @@ function main(){ mac) check_and_warn "brew " brew check_and_warn "wget " wget - check_and_install "minikube ($VERSION_MINIKUBE) " minikube - check_and_install "docker ($VERSION_DOCKER)" docker + check_and_install "k3d ($VERSION_K3D) " k3d check_and_install "kubectl ($VERSION_KUBECTL) " kubectl - check_and_install "helm ($VERSION_HELM) " helm - check_and_warn "virtualbox " virtualbox + check_and_install "helm ($VERSION_HELM) " helm check_and_warn "jq " jq #check_and_warn "git " git check_and_warn "python3 " python3 @@ -582,11 +428,9 @@ function main(){ alpine) check_and_warn "openssl " openssl check_and_warn "wget " wget - check_and_install "minikube ($VERSION_MINIKUBE) " minikube - check_and_install "docker ($VERSION_DOCKER)" docker + check_and_install "k3d ($VERSION_K3D) " k3d check_and_install "kubectl ($VERSION_KUBECTL) " kubectl check_and_install "helm ($VERSION_HELM) " helm - #check_and_install "virtualbox " virtualbox check_and_warn "jq " jq #check_and_warn "git " git check_and_warn "python3 " python3 @@ -599,19 +443,15 @@ function main(){ ubuntu) #check_and_install "openssl " openssl check_and_warn "wget " wget - check_and_install "minikube ($VERSION_MINIKUBE) " minikube - check_and_install "docker ($VERSION_DOCKER)" docker + check_and_install "k3d ($VERSION_K3D) " k3d check_and_install "kubectl ($VERSION_KUBECTL) " kubectl check_and_install "helm ($VERSION_HELM) " helm - #check_and_install "virtualbox " virtualbox check_and_warn "jq " jq #check_and_warn "git " git check_and_warn "python-pip " pip check_and_warn "python3 " python3 check_and_warn "aws-cli " awscli - check_and_warn "socat (optional; needed if minikube.vm_driver = none)" socat || : - # Only validate the script install at the end echo "$SCRIPT_HASH" > "$ALREADY_INSTALLED_FILE" diff --git a/scripts/install_nfs_mounts.sh b/scripts/install_nfs_mounts.sh deleted file mode 100755 index 4c6374c..0000000 --- a/scripts/install_nfs_mounts.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -case "$OSTYPE" in - cygwin*) - export_dir="/cygdrive/c/Users" - mount_dir="/c/Users" - ;; - linux*) - export_dir="/home" - mount_dir="/home" - ;; - *) - export_dir="/Users" - mount_dir="/Users" - ;; -esac - -host_ip="192.168.99.1" -read -r -d '' bootlocal </dev/null -sudo mount -t nfs -o tcp,rw,hard,noacl,async,nolock ${host_ip}:${export_dir} ${mount_dir} -EOF - -echo -e "\\nInstalling persistent start-up script: /var/lib/boot2docker/bootlocal.sh" -minikube ssh -- "echo \"${bootlocal}\" | sudo tee /var/lib/boot2docker/bootlocal.sh >/dev/null" -minikube ssh -- "sudo chmod +x /var/lib/boot2docker/bootlocal.sh && sync" - -echo -e "\\nRunning start-up script manually to nfs mount ${mount_dir} directory" -minikube ssh -- "/var/lib/boot2docker/bootlocal.sh" - -echo -e "\\nTesting mounts" -echo "=============" -minikube ssh -- "mount | grep '${mount_dir}'" - -echo -e "\\nTesting directory" -echo "== ${mount_dir} =================" -minikube ssh -- "ls -al ${mount_dir}"