---
# System prepended metadata

title: Untitled

---

### How to run Minikube under Windows 

Minikube is a tool that runs a single-node Kubernetes cluster in a virtual machine on PC. 
It can be run under Window and Linux. 
https://kubernetes.io/docs/setup/learning-environment/minikube/

#### Install python and libraries ####

1. Windows users should to install the Build Tools for Visual Studio
https://visualstudio.microsoft.com/ru/downloads/
with options:
- C++ Build core features,
- C++ 2019 Redistribution Update,
- MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.24),
- Windows 10 SDK,
- C++ CMake tools for Windows,
- Testing tools core features - Build Tools,
- C++/CLI support for v142 build tools (1424),
- MSVC v141 - VS 2017 C++ x64/x86 build tools (v14.16),
- MSVC v140 - VS 2015 C++ build tools (v14.00).

2. Install python
3. twisted and pyopenssl are needed for the project and can be installed using pip from user with admin rights (Windows):

```sh
$ pip install -r /path/to/requirements.txt
```

or

```sh
$ pip install twisted
$ pip install pyopenssl
```

#### Install chocolatey from Windows admin console
chocolatey is the package manager for Windows. It is needed for easy installation of minikube. 

https://chocolatey.org/install

#### Install VirtualBox
Minikube runs on top of VirtualBox, so VirtualBox should be installed.

#### Install minikube and etc
 
All other software can be installed using chocolatey.

```sh
$ choco install minikube
$ choco install docker-cli
$ choco install kubernetes-helm
```
#### Choose echo server implementation
Example of python echoserver/echoclient code:
https://gitlab.com/asduev/k8s_test/blob/master/src/
Optional step is to check in local enviroment echo client-server connection works correctly, expected traces are seen.
*Note: python script should be run with a key '-u' if you want to see the logs*

#### Setup proxy settings
Minikube downloads images from internet. Proxy should be configured to start it.
Minikube API server should be accessible without proxy (NO_PROXY).
 
```sh
$ set HTTP_PROXY=http://proxy.te.mera.ru:8080
$ set HTTPS_PROXY=http://proxy.te.mera.ru:8080
$ set NO_PROXY=192.168.99.0/24
```

Commands to set environment variables in Power Shell:

```sh
Set-Item Env:NO_PROXY 192.168.99.0/24
Set-Item Env:HTTP_PROXY http://proxy.te.mera.ru:8080
Set-Item Env:HTTPS_PROXY http://proxy.te.mera.ru:8080
```

#### Run minikube cluster
By default minikube uses 2 GB RAM and 1 CPU.
```sh
$ minikube start
```

If minikube tries to use hyperv by default, virtualbox can be forcely chosen

```sh
minikube start  --vm-driver=virtualbox
```

After minikube starts check there is no warning like this:
```
! You appear to be using a proxy, but your NO_PROXY environment does not
include the minikube IP (192.168.99.101). Please see
https://minikube.sigs.k8s.io/docs/reference/networking/proxy/ for more
details
```

If there is a warning adjust NO_PROXY network to include minikube ip address.

#### Setup Docker env
Minikube includes docker daemon, so it's possible to build your own image inside minikube cluster.

Docker cli should be configured to access docker daemon each time when minikube is started:

```sh
$ minikube docker-env
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\aduev\.minikube\certs
REM Run this command to configure your shell:
REM @FOR /f "tokens=*" %i IN ('minikube docker-env') DO @%i
```
Run command from output. Example of output:
```sh
$ @FOR /f "tokens=*" %i IN ('minikube docker-env') DO @%i
```
#### Build docker image
Kubernetes can download images from internet if you specify them in yaml file.
If you need run yor own software or script you should be built your own image:
 - Create docker file
   *Note: python script should be run with a key '-u' if you plan to check container's logs*
 - Build image
```sh
$ docker build --tag tls_echo --build-arg https_proxy=http://proxy.te.mera.ru:8080 --build-arg http_proxy=http://proxy.te.mera.ru:8080 .
```

If all environment variables are set correctly and image built passed, your image will be available for docker inside minikube VM

```
> minikube ssh
                          _             _
            _         _ ( )           ( )
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$ docker image ls
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
tls_echo                                  latest              034fc10de01b        24 seconds ago      921MB
...

```

#### Deploy your application in kubernetes
To run your application in kubernetes you should create yaml file to specify deployment.

The official documentation is very good. It's recommended to read it first:

https://kubernetes.io/docs/concepts/

Note the pods themselves are not very useful, so better solution is to use Deployment/StatefulSet for your application.
Consider adding PersistentVolume/PersistentVolumeClaim to store data and Service to distribute the load among the pods.

When you're ready with yaml file run your pod/pods:
```sh
$ kubectl apply -f internal_client.yaml
```

#### Troubleshooting
It's possible to open minikube dashboard in browser to check errors and check/edit current configuration YAMLs: 

```sh
$ minikube dashboard
```

There is a way to login inside pod and run shell:

```sh
aduev@N104149 C:\local\Work\proj\k8s_tls_echo
$ kubectl get pod   echoclient-deployment-54dcdddb4c-gbknw
NAME                                     READY   STATUS    RESTARTS   AGE
echoclient-deployment-54dcdddb4c-gbknw   1/1     Running   0          7m16s

aduev@N104149 C:\local\Work\proj\k8s_tls_echo
$ kubectl exec -it echoclient-deployment-54dcdddb4c-gbknw -- /bin/sh
```

Also container 'stdout' logs can be requested via 'docker' API inside of minikube VM

```
> minikube ssh
                         _             _
            _         _ ( )           ( )
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS               NAMES
e463303a8f6d        034fc10de01b           "python -u source.py"    5 minutes ago       Up 5 minutes                            k8s_hello_hello-5d6c58f459-
...

$ docker logs e463303a8f6d
======== Running on http://0.0.0.0:5858 ========
(Press CTRL+C to quit)
received request
Request:
<Request POST /chat >
```