skippbox / kmachine

Docker machine variant to create a single node Kubernetes instance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

env command does not support windows

sebgoa opened this issue · comments

We need to add windows (powershell) support for the kmachine env command.

Hey,

What is your philosophy for windows ?
Running docker-toolbox from Powershell or other terminals, brings some issues (tty and lot's of different problems). The only one that seems to work fine is Quick Launch Terminal.

Another point is clearly kubectl as it can't be installed on windows. For now I use a container with gcloud/kubectl to run all the commands from a windows host. So what is your feeling about that ? The credentials just need to be volume shared and it should be fine.

I'm working on project of virtual machine to setup a kubernetes for easy deployment/development. For now I didn't really know what was the good approach (Vagrant ? only docker ? ... each braings problems).
Your approach with kmachine is really great. As I just wrote before, kubectl can gives some problems. But maybe a container based approach can work here.

No, I didn't know that an official .exe have been released. Will definitely have a look. Thank you.

with MINGW64 (Docker Quick Launch Terminal): To make the setup work, we need to change one of your kmachine.exe env ${machineName}.

To do that:

cd ${YOUR_KMACHINE_FOLDER}
./kmachine.exe create dev
./kmachine env dev > env.sh

Then open env.sh and update the line

kubectl config set-cluster dev \
  --server=https://192.168.99.101:6443 \
  --certificate-authority=C:\Users\YOUR_USERNAME\.kube\machine\machines\dev/ca.pem

to something like that :

kubectl config set-cluster dev \
  --server=https://192.168.99.101:6443 \
  --certificate-authority=/C/Users/YOUR_USERNAME/.kube/machine/machines/dev/ca.pem 

finally, import the env:

. ./env.sh

Note that you will have to do that each time you create a new kmachine

ENV is just the top of the iceberg, I have tested addons setup and all of them doesn't work as windows have lots of specificities ...

The way I have done for this portability issue is to run everything in a container:

  • I have a really simple bash script that start a container that run a cli
  • I use the containerised cli to do all the stuff I need

In this way, everything can be run from any kind of environment that have only docker. So we can forget that windows compatibility that doesn't simplify the work for everyone ....

For now the tool I'm working on is hive. It's focused on developper and not devops so most of the tools won't really help you directly. But maybe we can look to map your different project (like addons) in order to simplify users life:

For now, I run kubectl like this:

$ ./hive kubernetes cli get nodes

No need for any installation. Hive is just a bash of less than 30 lines.

Maybe I can look in something like:

$ ./hive kmachine get_env
$ ./hive kmachine start_addons

etc ...

How do you feel with this approach ?

One approach we could take on windows at first:

  • point user to install docker-toolbox (Add bash, docker client, virtualbox), so we don't have to manage that part
  • create a bash script that replace the start.sh of docker-toolbox, this one could:
    • download kmachine if not present
    • create/start kmachine based on the docker-toolbox script

The process for new user would be:

  • download docker-toolbox
  • execute something like curl https://some-kmachine-url/windowsboot.sh | bash. The script would:
    • download and install kmachine
    • replace the quickTerminal start.sh (or create a new shortcut pointing to our start.sh)
  • start a QuickTerminal that would now point to kmachine

I was looking to start kmachine from hive but it's not intuitive as for now you need MINGW64 first .... like egg and chicken ...


Note: if we know how to install all this things by using bash (Virtualbox, git (for bash), MINGW64), we can at that moment add an install command on hive that make sense:

  • start a new project
  • curl hive
  • generate your project template
  • init and install dependencies (kmachine, vbox, ...)
  • ...

Some advance on that topic.

I have re-written the docker-toolbox start.sh.

I'm on the pattern:

  1. install docker-toolbox
  2. update start.sh with kmachine-start.sh
For now, the script:
  • control vitrualbox
  • download kmachine and install it in the /c/Users/<username>/.kube folder
  • control kmachine existance and create it if needed
  • control kmachine status and restart it if needed
  • add a command hive_install to easily install the hive script in a folder (we will be able to run kubectl with it) -- note that we could add a kubectl function too to make hive more optional (plz no ;-) )

I think it could be a good place to add function and alias.

issue

The environment import is the breaking point ^^

$ ./start.sh TEST

no kmachine in PATH, downloading in the current path
====================================================

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   605    0   605    0     0    968      0 --:--:-- --:--:-- --:--:--  1074
100 37.3M  100 37.3M    0     0  4563k      0  0:00:08  0:00:08 --:--:-- 6846k
Creating CA: C:\Users\shinm\.kube\machine\certs\ca.pem
Creating client certificate: C:\Users\shinm\.kube\machine\certs\cert.pem
Running pre-create checks...
Creating machine...
Waiting for machine to be running, this may take a few minutes...
Machine is running, waiting for SSH to be available...
Detecting operating system of created instance...
Provisioning created instance...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Configuring kubernetes...
Copying certs to the remote system...
To see how to connect Docker to this machine, run: C:\Users\shinm\.kube\bin\kmachine.exe env dev
./start.sh: line 100: kubectl: command not found
Looks like something went wrong... Press any key to continue...

./start.sh: line 100: kubectl: command not found ==> no kubectl.

The solution, is I think at this line 100 of the gist:

eval "$(${KMACHINE} env --shell=bash ${VM})"

I could replace --shell=bash with something like --shell=bash-whitout-kubectl.

Is this part of the code in your hands ? If yes, just return env for bash without the kubectl and we should be fine.

@Runseb any feedback on that ? :D
wrong direction ?

Just a point on something I said that was wrong: to invoke kubcetl.exe on windows, you can run kubcetl or kubcetl.exe. There is no difference. As kubectl can be downloaded really easily, I will add kubcetl download to the script.

@tdeheurles just did not have time to look at it. We are working on getting 1.2.0 out with embedded add-ons. Will get back to this in the coming week. Thanks for your patience

Ok, thanks.

Just for information, kubernetes on docker seems to work now. I have it started with DNS/Dashboard working. But as kubernetes is large, it's hard to tell if everything is working ...