Kubernetes on your laptop using Rancher 2.3 on Windows 10 with Minikube and Helm

Jason Yee
6 min readFeb 7, 2020

--

This story has been updated for Rancher 2.4 with k3s: https://medium.com/@jyeee/rancher-2-4-14c31af12b7a

This story is a follow up to https://medium.com/@jyeee/rancher-2-3-on-macos-with-minikube-and-helm-e83d26fb9552

After getting a little experience with Kubernetes, I can’t think of a better way to achieve the dream of “write once run everywhere” than an app containerized and deployed to k8s! On top of k8s, I’ve found Rancher to be the best interface for deploying apps and operating/maintaining the cluster.

I’m fortunate to work at a great company (https://www.techint.us/) that gives me access to amazing resources where I can run multiple clusters. For my home projects where I may not have those resources, I wanted to set up a lab on my laptop so I could practice.

This article details how I set up a minimal Rancher dev env using Minikube on Windows 10, adapting this article from the Rancher blog for a new Rancher version (Rancher 2.3), a new Helm version (Helm 3), and a new decade 🎉

Prerequisites

  • Windows 10 with Hyper-V

Seriously, that’s it! We’ll use chocolatey to help, but otherwise don’t need anything else.

Enable Hyper-V

Hyper-V is allows you to run a virtual host that runs the minikube kubernetes cluster.

If you haven’t done work with Hyper-V before, you may have to enable it with this command (read more at https://github.com/kubernetes/minikube/issues/2954)

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

Install Chocolatey

Chocolatey is a command-line package manager for Windows, and it feels like the Homebrew tools in macOS. We’re installing it here because one of the packages Chocolatey provides is Minikube,

I followed the instructions here https://chocolatey.org/install#individual

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1'))
this is what cURL looks like in Windows 10 in 2020

Install & start Minikube and enable the ingress addon

Now that we’ve got Hyper-V, let’s install Minikube and turn on required addons so that we can go to rancher.localdev to manage our cluster. We’ll also use minikube ip to know what IP the cluster is using. I’m going to use more CPUs and more memory than the defaults so this goes a little faster.

minikube start --cpus 4 --memory 4096minikube addons enable ingressminikube ip

Edit /etc/hosts

Now that you have your minikube IP (mine is 172.18.12.69), edit your hosts file that will map the IP to the domain name rancher.localdev. In Windows, this file is in C:\Windows\System32\drivers\etc\

Install helm for Rancher and its dependencies…and everything else!

Helm is the package manager for Kubernetes. It’s a similar pattern to chocolatey where you can install things without as many manual steps/clicks. Fortunately, we can use chocolatey to install helm (see https://helm.sh/docs/intro/install/)!

choco install kubernetes-helm

Install cert-manager, the prereq for Rancher

We’ll follow the instructions from this fantastic blog post from Rancher and update a few things for 2020. To deploy Rancher via helm, you’ll need to install cert-manager first. The standard way to deploy a workload via helm is to:

  1. Create a namespace for the deployment
  2. Install the helm repo
  3. Run the helm deployment

Kubernetes wants to give us a secure environment and part of that is enabling secure transfers (via TLS/SSL) by default. cert-manager is an “app” that provides this service.

For cert-manager, there are two extra steps to take, and you will have to install the CustomResourceDefinition resources and label the cert-manager namespace to disable resource validation.

We’ll use our recently installed helm app to install cert-manager. Note how we’ll use kubectl to apply some settings including a “namespace” which is like a separate network with its own DNS server. In other words, in a namespace, you can reference other servers by their name like “elasticsearch-worker-0” but outside of the namespace you can’t resolve that host.

Note how I use kubectl to get the pods to confirm that all of the cert-manager pods are running

# Install the CustomResourceDefinition resources separately
kubectl apply --validate=false -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.12/deploy/manifests/00-crds.yaml
# Create the namespace for cert-manager
kubectl create namespace cert-manager
# Label the cert-manager namespace to disable resource validation
kubectl label namespace cert-manager certmanager.k8s.io/disable-validation=true
# Add the Jetstack Helm repository
helm repo add jetstack https://charts.jetstack.io
# Update your local Helm chart repository cache
helm repo update
# Install the cert-manager Helm chart
# Note with helm 3 Usage: helm install [NAME] [CHART] [flags]
helm install cert-manager jetstack/cert-manager --namespace cert-manager --version v0.12.0
kubectl.exe -n cert-manager get pods,services,ingresses

Deploy Rancher

Deploying rancher is much more straightforward now that we’ve got helm installed! It may take a minute or so to get the Rancher containers up and running.

helm repo add rancher-stable https://releases.rancher.com/server-charts/stablehelm repo updatekubectl create namespace cattle-systemhelm install rancher rancher-stable/rancher --namespace cattle-system --set hostname=rancher.localdev

Install Elasticsearch in Rancher

Now that we’ve got Rancher up and running, navigate to https://rancher.localdev in your browser. You’ll pick your own password, confirm your server url and should see a running cluster!

If you see this error below where the cluster stays stuck at provisioning, edit the cluster by clicking the option dots and then and click save without changing anything in the ensuing dialog.

Edit the cluster if you get stuck in this Provisioning state
Running cluster managed by Rancher!

To deploy an app, you need to select a namespace. In the Rancher UI, go to Global > local > Default from the upper left side. Once in the Default namespace, click the button to deploy.

In this Deploy Workload UI, fill in the following as shown in the screenshot.

  • Name: es
  • Workload Type: Stateful set of 1 pod
  • Docker Image: elasticsearch:7.5.2
  • Port Mapping: nodeport 9200
  • Environment Variables: discovery.type = single-node

Hit Save at the very bottom to launch your cluster! If you do a kubectl get all you should see something like this showing Elasaticsearch up and running. You can confirm it by going to

Install Kibana in Rancher

  • Name: kibana
  • Docker Image: docker.elastic.co/kibana/kibana-oss:7.5.2
  • Port Mapping: nodeport 5601
  • Environment Variables: ELASTICSEARCH_HOSTS = http://es:9200
Note plural ELASTICSEARCH_HOSTS

Here’s what a deployment looks like when it’s not ready with a 0/1 READY status.

Here’s what a deployment looks like when it is ready!

Browse to the minikube IP and port from the service. From the Rancher Services Discovery tab, you can see the exposed ports. The contents of this page were automatically created by Rancher, how convenient!

In this case, it’s 172.17.109.167:32053. Later, we can connect this service to a load balancer and a DNS that points to it.

Enjoy!

Come join me at (https://www.techint.us/)! https://www.linkedin.com/in/jyeee/

--

--

Jason Yee

Husband/Dad, problem solver, technologist, citizen airman, Eagle Scout ♥️🇺🇸