Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node...

12
Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides you through all the steps required to create and configure a Minikube cluster on Windows 10. Kubernetes 1 runs on Linux. As such, Minikube 2, 3 is a tool that makes it easy to run Kubernetes locally for development and testing. Although Windows 10 now has some very useful features, such as the ability to install Ubuntu as an app, the integration of Windows Subsystem for Linux 2 (WSL2) doesn’t provide (yet) all the Ubuntu functionalities required to make Minikube run smoothly right out-of-the-box (OOB) along with the Docker Engine - Community for Ubuntu. If you wish to experiment by yourself, see for example Support for Windows 10 WSL2. For now, and for the sake of simplicity for anyone looking to try out Kubernetes on Windows 10, let’s run Minikube on Windows 10 with virtualization. Minikube will be run on without problems on a virtual machine (VM) with Hyper-V. You will follow this path in this walkthrough. See also Setting up Kubernetes on Windows10 Laptop with Minikube. So, let’s start by configuring the Hyper-V environment on your Windows 10 local machine. Enabling Hyper-V The Windows 10 Hyper-V System requires: Windows 10 Enterprise, Pro, or Education 64-bit Processor with Second Level Address Translation (SLAT). CPU support for VM Monitor Mode Extension (VT-c on Intel CPUs). Minimum of 4 GB memory. Note For more information and troubleshooting, see Windows 10 Hyper-V System Requirements. Perform the following steps: 1. Open a PowerShell console as an Administrator, and check if virtualization is supported: PS C:> systeminfo If you see the following output, virtualization is supported. You can proceed with the next steps. Hyper-V Requirements: VM Monitor Mode Extensions: Yes Virtualization Enabled In Firmware: Yes 1 https://kubernetes.io/ 2 https://minikube.sigs.k8s.io/ 3 https://github.com/kubernetes/minikube

Transcript of Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node...

Page 1: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

Install a Minikube single node cluster locally on Windows 10

By Philippe Beraud, Microsoft France

This walkthrough guides you through all the steps required to create and configure a Minikube

cluster on Windows 10.

Kubernetes1 runs on Linux. As such, Minikube2, 3 is a tool that makes it easy to run Kubernetes locally

for development and testing.

Although Windows 10 now has some very useful features, such as the ability to install Ubuntu as an

app, the integration of Windows Subsystem for Linux 2 (WSL2) doesn’t provide (yet) all the Ubuntu

functionalities required to make Minikube run smoothly right out-of-the-box (OOB) along with the

Docker Engine - Community for Ubuntu. If you wish to experiment by yourself, see for example

Support for Windows 10 WSL2.

For now, and for the sake of simplicity for anyone looking to try out Kubernetes on Windows 10, let’s

run Minikube on Windows 10 with virtualization. Minikube will be run on without problems on a virtual

machine (VM) with Hyper-V. You will follow this path in this walkthrough. See also Setting up

Kubernetes on Windows10 Laptop with Minikube.

So, let’s start by configuring the Hyper-V environment on your Windows 10 local machine.

Enabling Hyper-V

The Windows 10 Hyper-V System requires:

• Windows 10 Enterprise, Pro, or Education

• 64-bit Processor with Second Level Address Translation (SLAT).

• CPU support for VM Monitor Mode Extension (VT-c on Intel CPUs).

• Minimum of 4 GB memory.

Note For more information and troubleshooting, see Windows 10 Hyper-V System Requirements.

Perform the following steps:

1. Open a PowerShell console as an Administrator, and check if virtualization is supported:

PS C:> systeminfo

If you see the following output, virtualization is supported. You can proceed with the next

steps.

Hyper-V Requirements: VM Monitor Mode Extensions: Yes Virtualization Enabled In Firmware: Yes

1 https://kubernetes.io/ 2 https://minikube.sigs.k8s.io/

3 https://github.com/kubernetes/minikube

Page 2: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

Second Level Address Translation: Yes Data Execution Prevention Available: Yes

If you see the following output, your system already has a Hypervisor installed and you can

skip the steps 3-4 below.

Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.

Otherwise, virtualization is unfortunately not supported on your machine, and you cannot

continue with this walkthrough.

2. Run the following command:

PS C:> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

Note If the command couldn't be found, make sure you're running PowerShell as Administrator.

3. Once the installation has completed, reboot your Windows 10 machine.

4. With the Hyper-V driver, Minikube takes the first virtual switch found, which should be the

“Default Switch” for a default Hyper-V installation. Minikube no longer requires a virtual switch

of type “External” to function. See Microsoft Hyper-V driver.

However, to further facilitate the integration with WSL2, you will create one.

a. Get the list of network adapters to attach to:

PS C:\> Get-NetAdapter

b. Create the virtual switch:

PS C:\> New-VMSwitch -name minikube -NetAdapterName <your_network_adapter> -AllowManagementOS $true

You can choose for example the WiFi adapter as in our configuration:

Page 3: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

PS C:\> New-VMSwitch -name minikube -NetAdapterName "WiFi" -AllowManagementOS $true

Installing the Minikube cluster

Let’s start by installing Chocolatey to ease to your installation.

Installing Chocolatey

See Installing the Chocolatey Package manager for Windows and Using Windows? Do yourself a favor

and install chocolatey!.

To install the Chocolatey package manager, perform the following steps:

1. Open a Windows command line prompt as an Administrator.

2. Run the following command.

PS C:\> @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

If you want a visual experience for Chocolatey packages, you can also install a GUI for

Chocolatey. Run the following command:

PS C:\> choco install chocolateygui

Page 4: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

Installing kubectl

The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters.

You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. See

Overview of kubectl.

Perform the following steps:

1. Open a PowerShell console as an Administrator.

2. Install the latest version available of the Chocolatey kubectl package, 1.17.1 as of this writing,

as per version history:

PS C:\> choco install kubernetes-cli

To otherwise install a specific version, set the –-version argument as follows:

PS C:\> choco install kubernetes-cli --version=1.16.2

Note As per official documentation, you must use a kubectl version that is within one minor version

difference of your cluster. For example, a v1.2 client should work with v1.1, v1.2, and v1.3 master. Using the

latest version of kubectl helps avoid unforeseen issues.

z

3. Navigate the %HOMEPATH%\.kube folder. Have a look!

Installing Minikube

Now, you will install Minikube for Windows (and not the Linux version in WSL2 as it will not work. See

the introduction of this walkthrough).

See Install Minikube.

Perform the following steps:

1. Open a PowerShell console as an Administrator.

Page 5: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

2. Run the following command:

PS C:\> choco install minikube

After Minikube has finished installing, close the current PowerShell console.

3. Reopen a PowerShell console as an Administrator. Minikube should have been added to your

path automatically. Navigate the %HOMEPATH%\.minikube folder. You will notice several

folders are created. Have a look!

4. Get the version of Minikube:

PS C:\> minikube.exe version minikube version: v1.6.2 commit: 54f28ac5d3a815d1196cd5d57d707439ee4bb392

5. Start up a local Kubernetes cluster with the Hyper-V driver. Make sure you define hyperv-

virtual-switch flag, which should point to the external network switch you have created

previously.

PS C:\> minikube start --vm-driver=hyperv --hyperv-virtual-switch="minikube v switch" * minikube v1.6.2 on Microsoft Windows 10 Pro 10.0.19546 Build 19546 * Selecting 'hyperv' driver from user configuration (alternates: []) * Downloading VM boot image ... > minikube-v1.6.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s > minikube-v1.6.0.iso: 150.93 MiB / 150.93 MiB [-] 100.00% 3.49 MiB p/s 44s * Creating hyperv VM (CPUs=2, Memory=2000MB, Disk=20000MB) ... * Preparing Kubernetes v1.17.0 on Docker '19.03.5' ... * Downloading kubeadm v1.17.0 * Downloading kubelet v1.17.0 * Pulling images ... * Launching Kubernetes ... * Waiting for cluster to come online ... * Done! kubectl is now configured to use "minikube"

Page 6: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

Note You can also set couple of global flags like --v=7 and --alsologtostderr to see what is going

on under the hood

Let’s understand what the above command is doing behind the scene:

• It will start downloading the minikube minikube-v1.6.0.iso file.

• Once the ISO download completes, a new Minikube VM will be created in Hyper-V.

• It will start downloading the localkube binaries (kubeadm and kubelet).

• At the end, it configures the Kubectl to use the local Kubernetes cluster.

On success, you will get the messaging stating “Done! Kubectl is now configured to use the

cluster.”

Minikube adds the configuration to your %USERPROFILE%\.kube\config file upon successful

creation so you should be able to connect to the Minikube cluster from the PowerShell

console using kubectl.

6. The IP address of the cluster is dynamic and can change. Retrieved it:

PS C:\> minikube ip 192.168.1.81

7. Check the status of the Minikube cluster:

PS C:\> minikube status host: Running kubelet: Running apiserver: Running kubeconfig: Configured

Note If you run into issues, see Issues · kubernetes/minikube · GitHub.

Page 7: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

After you have confirmed whether Minikube is working with your chosen hypervisor, you can

continue to use Minikube or you can stop your cluster (and then possibly delete your cluster).

a. To stop your cluster, run the following command:

PS C:\> minikube stop * Stopping "minikube" in hyperv ... * Powering off "minikube" via SSH ... * "minikube" stopped.

b. To then delete your cluster, run the following command:

PS C:\> minikube delete * Successfully powered off Hyper-V. minikube driver -- hyperv * Deleting "minikube" in hyperv ... * The "minikube" cluster has been deleted. * Successfully deleted profile "minikube"

8. For the moment, get the cluster information:

PS C:\> kubectl config set-context minikube Context "minikube" modified. PS C:\> kubectl config use-context minikube Switched to context "minikube". PS C:\> kubectl cluster-info Kubernetes master is running at https://192.168.1.82:8443 KubeDNS is running at https://192.168.1.82:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

9. List the nodes:

PS C:\> kubectl get nodes NAME STATUS ROLES AGE VERSION minikube Ready master 3m22s v1.17.0

10. Run the Kubernetes dashboard.

PS C:\> minikube dashboard * Verifying dashboard health ... * Launching proxy ...

Page 8: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

* Verifying proxy health ... * Opening http://127.0.0.1:54383/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...

This will open up the dashboard window in your default browser at the URL

http://127.0.0.1:50115/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-

dashboard:/proxy/.

So, let’s now configure WSL2 as your command prompt in Windows 10 so that you can have kubectl,

helm and other tools all installed here for Kubernetes.

Configuring the WSL2 environment

See Setting up Kubernetes on WSL to work with Minikube on Windows 10 and Running Kubernetes

Minikube on Windows 10 with WSL.

WSL2 provides a genuine Linux Bash shell on Windows 10 via the installation of the supported distro(s)

of your choice as an app. To install and configure Ubuntu as an app, follow the related step-by-step

instructions as per walkthrough Install and configure WSL2 on Windows 10.docx. (Do NOT install

Docker Desktop WSL 2 backend.)

As this stage, the rest of this document assumes that you have a fully configured WSL2

environment on your Windows 10 local machine.

Page 9: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

Installing kubectl

See Install kubectl on Linux.

Perform the following steps:

1. From the Bash terminal console, install the latest version of kubectl:

$ sudo apt-get update && sudo apt-get install -y apt-transport-https $ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - $ echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list $ sudo apt-get update $ sudo apt-get install -y kubectl

To otherwise install a specific version of kubectl, you will need to use curl install, for example

for version 1.16.0

$ curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl $ chmod +x kubectl $ sudo mv kubectl /usr/local/bin/

2. Get the version of kubectl:

$ kubectl version --client=true Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}kube

Using kubectl

As you saw, with the above installation of Minikube on Windows 10, the .kube/config file was created

on the Windows 10 side: %USERPROFILE%\.kube\config. To get kubectl to work, you will need to add

the configuration to your config file on WSL2 at $HOME/.kube.

To do so, perform the following steps:

1. Open a PowerShell console as an administrator.

2. Run the following commands:

PS C:\> kubectl config view

The configuration values created on for your Windows 10 environment are dumped. They

might vary depending on your existing .kube/config file and set up. See Configure Access to

Multiple Clusters.

apiVersion: v1 clusters: - cluster: certificate-authority: C:\Users\philber\.minikube\ca.crt server: https://192.168.1.81:8443 name: minikube contexts: - context: cluster: minikube user: minikube

Page 10: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

name: minikube current-context: minikube kind: Config preferences: {} users: - name: minikube user: client-certificate: C:\Users\philber\.minikube\client.crt client-key: C:\Users\philber\.minikube\client.key

You will need to change the certificate-authority, client-certificate and

the client-key so that WSL2 can find the certificates in your Windows 10 local machine.

3. From a Bash terminal console on the WSL2 side, add the Minikube context info:

$ kubectl config set-cluster minikube --server=https://<minikube_ip>:<minikube_port> --certificate-authority=/mnt/c/Users/<your_username>/.minikube/ca.crt $kubectl config set-credentials minikube --client-certificate=/mnt/c/Users/<your_username>/.minikube/client.crt --client-key=/mnt/c/Users/<your_username>/.minikube/client.key $kubectl config set-context minikube --cluster=minikube --user=Minikube

Where:

• <minikube_ip>is the IP address of your Minikube cluster.

• <minikube_port> is the port used by your Minikube cluster.

• <your_username> is the Windows account under which you installed Minikube.

For example, in our configuration:

$ kubectl config set-cluster minikube --server=https://192.168.1.81:8443 --certificate-authority=/mnt/c/Users/philber/.minikube/ca.crt $ kubectl config set-credentials minikube --client-certificate=/mnt/c/Users/philber/.minikube/client.crt --client-key=/mnt/c/Users/philber/.minikube/client.key

4. Now view the context in WSL2:

$ kubectl config set-context minikube --cluster=minikube --user=minikube Context "minikube" modified.

5. Verify that you have set the values correctly - If you have other contexts if might look slightly

different -:

$ kubectl config view apiVersion: v1 clusters: - cluster: certificate-authority: /mnt/c/Users/philber/.minikube/ca.crt server: https://192.168.1.81:8443 name: minikube contexts: - context: cluster: minikube user: Minikube name: minikube current-context: minikube kind: Config preferences: {}

Page 11: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

users: - name: minikube user: client-certificate: /mnt/c/Users/philber/.minikube/client.crt client-key: /mnt/c/Users/philber/.minikube/client.key

6. Try connecting to your Minikube cluster:

$ kubectl config use-context minikube $ kubectl get nodes

You can now use kubectl as you would with any other cluster.

Kubernetes is meant for deploying apps and services. So, at this stage, you can further test your

Minikube cluster.

Creating a test deployment on the Minikube cluster

See Installing Kubernetes with Minikube.

To install a first app, perform the following steps:

1. From the VM Shell, deploy NGINX with 3 replicas (instances) available:

$ kubectl run nginx --image nginx:alpine --replicas 3 kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead. deployment.apps/nginx created

2. It may take a minute or two to install, but you can check the status. Once NGINX has been

deployed, expose the application:

$ kubectl expose deployment nginx --port 80 --target-port 80 --type ClusterIP --selector=run=nginx --name nginx service/nginx exposed

3. See the new Service and ClusterIP address assigned:

$ kubectl get svc kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6m29s nginx ClusterIP 10.96.42.243 <none> 80/TCP 23s

Page 12: Install a Minikube single node cluster locally on Windows 10...Install a Minikube single node cluster locally on Windows 10 By Philippe Beraud, Microsoft France This walkthrough guides

4. Run the Kubernetes dashboard:

5. Hopefully, all of that is working. So, let’s remove the service and pod you have deployed:

$ kubectl delete service nginx service "nginx" deleted $ kubectl delete deployment nginx deployment.apps "nginx" deleted

At this stage, you have a Minikube cluster running, and it’s a clean copy ;-)

This concludes this walkthrough. You can now start using your Minikube single node cluster the

way you expect on your Windows 10 machine. This is great for technical ram-up on Kubernetes,

local development, and CI/CD.

Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)