Skip to content

Instantly share code, notes, and snippets.

@labrown
Last active December 7, 2021 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save labrown/8fc8891495dad868867fcbfaaa5c6a3a to your computer and use it in GitHub Desktop.
Save labrown/8fc8891495dad868867fcbfaaa5c6a3a to your computer and use it in GitHub Desktop.

Running Microk8s cluster locally on Windows 10

This is a work in progress and will be expanded and improved as I have time.

Sources

I started with the MicroK8s documentation at https://ubuntu.com/tutorials/install-a-local-kubernetes-with-microk8s#1-overview. I didn't choose the multipass route because I like yak-shaving my VMs manually and wanted to get as much understanding of what's going on as possible.

This PDF helped me set up Hyper-V on my windows desktop. My rig is:

  • Ryzen 7 3700X
  • 32GB RAM

so I have plenty of horsepower and memory to go around.

Configure Hyper-V and create an Ubuntu 20.04.3 VM

I used this GeekFlare page https://geekflare.com/ubuntu-on-windows/ to configure Hyper-V and create the Ubuntu 20.04.3 LTS VM for MicroK8s.

Follow the directions in it to:

  1. Enable Virtualization
  2. Enable Hyper-V
  3. Create a Virtual Switch for the VMs The Virtual Switch is needed to give the VM access to the external network. The default switch in Hyper-V is host-only. I find it easier to treat the VMs as normal servers on my network rather than having them all NATted behind a non-routable network.
  4. Create an Ubuntu 20.04.3 LTS VM using the 'Installing Manually' method. Select Generation 1 After creating the VM, go into its Settings and make these changes:
    1. Adjust the virtual CPUs to 2
    2. Add a second NIC. I enabled VLAN 2 on my home network and configured the second NIC to use it, so that I can clearly see the different IP addresses on the two NICs
    3. Start the installation process
    4. When it asks for what snaps you want to install, select microk8s, then continue.

Configure microk8s

  1. Log into your VM
  2. Install kubectl using the apt-get as per: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-using-native-package-management
  3. Verify microk8s is up and running
microk8s status
  1. You should get something like this:
$ microk8s status
microk8s is running
high-availability: no
  datastore master nodes: 127.0.0.1:19001
  datastore standby nodes: none
addons:
  enabled:
    ha-cluster           # Configure high availability on the current node
  disabled:
    ambassador           # Ambassador API Gateway and Ingress
    cilium               # SDN, fast with full network policy
    dashboard            # The Kubernetes dashboard
    dns                  # CoreDNS
    fluentd              # Elasticsearch-Fluentd-Kibana logging and monitoring
    gpu                  # Automatic enablement of Nvidia CUDA
    helm                 # Helm 2 - the package manager for Kubernetes
    helm3                # Helm 3 - Kubernetes package manager
    host-access          # Allow Pods connecting to Host services smoothly
    ingress              # Ingress controller for external access
    istio                # Core Istio service mesh services
    jaeger               # Kubernetes Jaeger operator with its simple config
    kata                 # Kata Containers is a secure runtime with lightweight VMS
    keda                 # Kubernetes-based Event Driven Autoscaling
    knative              # The Knative framework on Kubernetes.
    kubeflow             # Kubeflow for easy ML deployments
    linkerd              # Linkerd is a service mesh for Kubernetes and other frameworks
    metallb              # Loadbalancer for your Kubernetes cluster
    metrics-server       # K8s Metrics Server for API access to service metrics
    multus               # Multus CNI enables attaching multiple network interfaces to pods
    openebs              # OpenEBS is the open-source storage solution for Kubernetes
    openfaas             # openfaas serverless framework
    portainer            # Portainer UI for your Kubernetes cluster
    prometheus           # Prometheus operator for monitoring and logging
    rbac                 # Role-Based Access Control for authorisation
    registry             # Private image registry exposed on localhost:32000
    storage              # Storage class; allocates storage from host directory
    traefik              # traefik Ingress controller for external access
lance@kates:~/$ 
  1. Create a kubectl config for your microk8s
$ microk8s config > ~/.kube/config
  1. test with normal kubectl
lance@kates:~/.kube$ kubectl get nodes
NAME    STATUS   ROLES    AGE   VERSION
kates   Ready    <none>   32m   v1.22.4-3+adc4115d990346
lance@kates:~/.kube$ 
  1. Enable some useful microk8s addons
$ sudo microk8s enable dns storage registry dashboard

This will take a while as microk8s pulls down all the images needed and fires up the deployments for each addon.

Your first deployment

I used this example from kubernetes.io: https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/

  1. Make a directory to work in
mkdir ~/wordpress
cd ~/wordpress
  1. Get the mysql-deployment.yaml
curl -LO https://k8s.io/examples/application/wordpress/mysql-deployment.yaml
  1. Get the wordpress-deployment.yaml
curl -LO https://k8s.io/examples/application/wordpress/wordpress-deployment.yaml
  1. Create the kustomization.yaml file. This adds a secretGenerator you use to specify the password for the mysql deployment. Replace YOUR_PASSWORD with the password you want to use
cat <<EOF >./kustomization.yaml
secretGenerator:
- name: mysql-pass
  literals:
  - password=YOUR_PASSWORD

resources:
  - mysql-deployment.yaml
  - wordpress-deployment.yaml
EOF
  1. Apply the configuration
$ kubens default
$ kubectl apply -k ./
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment