Install a Microk8s Single Node Cluster Locally on Windows 10
Total Page:16
File Type:pdf, Size:1020Kb
Install a MicroK8s 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 MicroK8s cluster on Windows 10. Kubernetes1 runs on Linux. As such, MicroK8s2 provides a single command installation of the latest Kubernetes release on a Linux machine for development and testing. MicroK8s is easy to install and use on Ubuntu or any other Linux distro which supports snaps, i.e. pre-packaged applications (similar to Docker containers). 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 MicroK8s run smoothly right out-of-the-box (OOB) and thus use the snap daemon. If you wish to experiment with running MicroK8s semi-natively, see: • Discourse post Using snapd in WSL2 • Post Running Snaps on WSL2 (Insiders only for now) along with the short YouTube video Use this ONE trick to run Linux Snap packages in Windows Subsystem for Linux 2 (WSL2) For now, and for the sake of simplicity for anyone looking to try out Kubernetes on Windows 10, let’s run MicroK8s on Windows 10 with virtualization. MicroK8s will install without problems on Ubuntu on a virtual machine (VM). The Canonical way to get a Linux VM on Windows 10 and to run MicroK8s in it is with multipass. Multipass gives you an easy to use interface to manage VMs on Windows 10 – Same is true on MacOS and Linux -. On Windows platforms, multipass defaults to using Microsoft Hyper-V as it’s virtualization provider. So, Microsoft Hyper-V is a prerequisite. (You can also take advantage of a local installation of VirtualBox if you want to.) Note For more information, see Instant Ubuntu VMs. 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. 1 https://kubernetes.io/ 2 https://github.com/ubuntu/microk8s 2. 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 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 next steps 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 can not continue with this walkthrough. 3. 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. 4. Once the installation has completed, reboot your Windows 10 machine. Creating the Ubuntu 18.04 LTS VM Perform the following steps: 1. Download and install multipass. The latest Windows 10 installer is available for download here on the multipass GitHub releases page. 2. Once multipass is installed, you can now create a VM to run MicroK8s. At least 4 Gb of RAM and 40 Gb of storage is recommended – you can pass these requirements when you launch the VM – a. Open a PowerShell console. b. Creates a new Ubuntu VM instance using the default, at this point in time, image: PS C:> multipass launch --name microk8s-vm --mem 4G --disk 40G It’s most likely going to be the latest cloud image of the newest Ubuntu LTS (Long Term Support) release, at the time of this writing a 18.04 LTS release. Note You can also choose another image, you can use the find command to see what’s available. Note For a complete listing of the available commands and their options in multipass, see the Command-line reference. When the command completes, a new VM named microk8s-vm is running. You can see it from the Hyper-V Manager. One should note that multipass uses the “Default Switch” network interface on Hyper-V, that, in turn, uses the “Internet Sharing” functionality, providing DHCP (IP addresses) and DNS (domain name resolution) to the instances. 3. Find the IP address which has been allocated to the VM: PS C:> multipass list Name State IPv4 Image microk8s-vm Running 172.22.82.139 Ubuntu 18.04 LTS Take a note of this IP as services will become available there when accessed from the Windows 10 host machine, see below. For example ,172.22.82.139 in our configuration. 4. To work within the VM environment more easily, get a shell inside the VM: C:\> multipass shell microk8s-vm This opens up a new Shell window: From within the VM shell, you can now follow along the rest of the quick start instructions for installing MicroK8s on multipass. Installing the MicroK8s cluster Perform the following steps: 1. Install the latest version of the MicroK8s snap: $ sudo snap install microk8s --classic Note Microk8s is a snap deploying Kubernetes. The MicroK8s snap closely follows upstream Kubernetes, so understanding a bit about the Kubernetes release cycle is helpful for more insight into MicroK8s releases. Upstream Kubernetes ships a new release series (e.g. 1.16.x) approximately every three months. For more information, see Snap channel overview. That’s all it takes for the installation, which is quick and painless! ;-) 2. MicroK8s has a built-in command to display its status (see hereafter). During installation you can use the --wait-ready flag to wait for the Kubernetes services to initialize. Check the status: $ sudo microk8s.status --wait-ready The microk8s-vm VM now runs a MicroK8s cluster on to of Ubuntu 18.04 LTS. MicroK8s comes with a set of tools: microk8s.start, microk8s.stop, microk8s.inspect, microk8s.status, microk8s.enable, microk8s.disable, microk8s.kubectl, microk8s.istioctl, and microk8s.config: • microk8s.start and microk8s.stop do what you would expect: start or stop your Kubernetes cluster. • microk8s.inspect gives you see the actual Kubernetes cluster status. • microk8s.status is a little less intuitive, as it shows the status of the add-ons and not the Kubernetes cluster status. You will use it alongside microk8s.enable and microk8s.disable to control add-ons. • microk8s.kubectl is a wrapper around kubectl, i.e. the cluster manager tool for Kubernetes. • microk8s.istioctl is used to control Istio, which can be enabled as an add-on via microk8s.enable istio. • microk8s.config, shows the client configuration that can be used to connect to your Kubernetes cluster, should you decide not to use microk8s.kubectl to do that. This command will result in output like the following: apiVersion: v1 clusters: - cluster: server: https://172.17.18.79:16443 name: microk8s-cluster contexts: - context: cluster: microk8s-cluster user: admin name: microk8s current-context: microk8s kind: Config preferences: {} users: - name: admin user: username: admin password: UFpWSGlHZDJuSkxpcCtJZ0JTU1dDK2d0eWk3NTdhZEg0TjVQcWVDc3Ywdz0K To feed this client config to microk8s.kubectl, you can for example write it to ~/.kube/config, i.e. the default configuration location. $ sudo microk8s.config > $HOME/.kube/config 3. Configure the network: $ sudo iptables -P FORWARD ACCEPT 4. MicroK8s creates a group to enable seamless usage of commands which require admin privilege. Add your current user to the group: $ sudo usermod -a -G microk8s ubuntu You will also need to re-enter the session for the group update to take place. 5. As mentioned above, MicroK8s bundles its own version of kubectl for accessing Kubernetes. Use it to run commands to monitor and control your Kubernetes. For example, view your node: $ microk8s.kubectl get nodes NAME STATUS ROLES AGE VERSION microk8s-vm Ready <none> 5m27s v1.17.0 6. Or alternatively see the running services: $ microk8s.kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 6m17s 7. MicroK8s uses a namespaced kubectl command to prevent conflicts with any existing installs of the Kubernetes command-line tool, kubectl. 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. If you don't have an existing install, it is easier to add an alias (append to ~/.bash_aliases) like this: $ sudo snap alias microk8s.kubectl kubectl Added: - microk8s.kubectl as kubectl Otherwise, from the Bash terminal console, to install the latest version of kubectl, run the following command: $ snap install kubectl –classic $ kubectl version See Install kubectl on Linux. At this stage, you have a fully functional Kubernetes cluster. Creating a test deployment on the MicroK8s cluster Kubernetes is meant for deploying apps and services. You now can use the kubectl (alias) command (or the microk8s.kubectl command) to do that as with any Kubernetes. 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 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 3. See the new Service and ClusterIP address assigned: $ kubectl get svc You now have a deployed an application to a fully functional Kubernetes cluster using Microk8s Further configuring the MicroK8s cluster MicroK8s uses the minimum of components for a pure, lightweight Kubernetes.