wuestkamp / cka-example-environments

112 stars 94 forks source link

Script seems to deliver random results #4

Open B45man opened 4 years ago

B45man commented 4 years ago

I'm on Windows 10, latest update. Got the latest version of both VirtualBox and Vagrant installed. The scripts don't work on Windows, so I converted them to powershell:

vagrant up --provider virtualbox

echo '######################## WAITING TILL ALL NODES ARE READY ########################'
sleep 60

echo '######################## INITIALISING K8S RESOURCES ########################'
#chmod 400 certs/id_rsa
vagrant ssh cluster1-master1 -c "sudo su - root -c 'kubectl apply -f /vagrant/k8s/init.yaml'"
vagrant ssh cluster1-master1 -c "mkdir -p .kube ; sudo cp /root/.kube/config ./.kube/config ; sudo chown vagrant:vagrant .kube/config"
sleep 20

echo '######################## ALL DONE ########################'

And

vagrant destroy --force
rm -r .vagrant
rm -r tmp
mkdir tmp
New-Item tmp/.gitignore

However, the script already seems to fail at the first vagrant up --provider virtualbox command. Sometimes installing kubectl seems to fail according to the logs, sometimes the second node can't be instantiated, it's a new random bug every time. The errors are very random. Does this script store state somewhere in a way that can affect subsequent runs?

wuestkamp commented 4 years ago

As of now Windows isn't supported as the init scripts are all written for bash. If you figure this out and make this work with Windows feel free to create a PR, that would be much appreciated :)

Does this script store state somewhere in a way that can affect subsequent runs?

Vagrant iteself stores state in a local .vagrant folder. I suggest you delete this one and try again to spin it up

Make sure to wait till all nodes area actually ready before applying the k8s resources from init.yaml.

B45man commented 4 years ago

My apologies, I appear to be having issues with Vagrant and VirtualBox on Windows. Your scripts are fine, sorry for implying otherwise.

The scripts I posted above are fine. It's the call to vagrant up --provider virtualbox that always seems to fail at different steps. Either steps time out, fail to connect through SSH, packages fail to install, or otherwise. And 1 in 5 times the scripts work as intended. I am assuming it's just Vagrants low quality on Windows platforms, as I have yet to have 100% success with any Vagrant file. I'm going to try Vagrant on Ubuntu instead to see if my luck changes.

garyttt commented 3 years ago

The scripts do work on Windows10 home edition 20H2 update with latest version of Vagrant (2.2.14) and VirtualBox (6.1), instead of installing GIT for Windows for running the "./up.sh" script, you may install RedHat CYGWIN64 to run "./up.sh".

Many kubernetes self-learners may be using Docker Desktop with built-in kubernetes engine enabled, i.e. single-node cluster.

For Windows 10 environment, I have found Docker Desktop and Vagrant-VirtualBox created k8s cluster are mutually exclusive.

If Docker Desktop is running, the "./up.sh' will fail at 'SSH auth method: private key' stage with the following message.

cluster1-master1: SSH auth method: private key

Timed out while waiting for the machine to boot. This means that Vagrant was unable to communicate with the guest machine within the configured ("config.vm.boot_timeout" value) time period.

The solution is to stop Docker Desktop, in Windows 10 start run Command Prompt as administrator and then reboot PC bcdedit /set hypervisorlaunchtype off

This will fix the private key setup issue.

On the other hand, if Docker Desktop is to be run:

The solution is to stop VirtualBox VMs, in Windows 10 start run Command Prompt as administrator and then reboot PC bcdedit /set hypervisorlaunchtype auto