Using Minikube with KVM¶
Enabling/Installing KVM¶
Minikube can run using the KVM driver. To use it, first you need to install KVM support in Ubuntu and also check that you've allowed VTx virtualization in your BIOS. The BIOS configuration is machine-dependent, read the specific documentation for your hardware on how to enable it.
The documentation in the Ubuntu Help pages has guidelines on the necessary steps to check if you're hardware is KVM-ready, and if so know how to install KVM support. Follow it before moving forward on enabling Minikube with the KVM driver.
Enabling Minikube with KVM support¶
Follow this K8s blog post to understand the steps involved in creating a Minikube K8s cluster with KVM support.
Getting the dashboard to work on a remote machine¶
Say you're running Minikube in your Linux server and you want to access the dashboard from an external machine (your Mac).
You need to get kubectl proxy
(the command that minikube dashboard
is running in the background) to bind to your all addresses in your machine instead of just localhost. You do that by doing:
MINIKUBE_HOST_IP=$(hostname -I | cut -f1 -d' ')
kubectl proxy --address 0.0.0.0 --accept-hosts $MINIKUBE_HOST_IP
Now, go to your Mac's browser and try: http://$MINIKUBE_HOST_IP:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
Note
If you forget the URL or it is messed up, you can get it from running minikube dashboard --url
from your Linux machine.
I've created a linux script in my ~/bin
directory in my Linux server called proxy_minikube_dashboard.sh
to automate this:
#!/usr/bin/env bash
MINIKUBE_HOST_IP=$(hostname -I | cut -f1 -d' ')
echo "Open the following URL in your laptop:"
echo "http://${MINIKUBE_HOST_IP}:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/"
kubectl proxy --address 0.0.0.0 --accept-hosts $MINIKUBE_HOST_IP
Exposing the Dashboard as a NodePort¶
If you want to expose the Dashboard as a NodePort (maybe you want to use a proxy like NGINX to access from an external host) is as simple as patching the service kubernetes-dashboard
in the namespace kubernetes-dashboard
.
First thing is to see the current service type and ports used. We are using go-template to show in the type port-->targetPort:type
:
kubectl get svc/kubernetes-dashboard \
-n kubernetes-dashboard \
-o template \
--template='{{range .spec.ports}}{{.port}}-->{{.targetPort}}{{end}}:{{.spec.type}}'
We'll see an output like this:
80-->9090:ClusterIP
Then we need to path the service type
to NodePort
and using the same ports.
So we create a k8s-dashboard-patch.yaml
file with the patch to apply (we are using a fixed NodePort
31001
in this example):
spec:
ports:
- port: 80
protocol: TCP
targetPort: 9090
nodePort: 31001
type: NodePort
And then we apply the patch:
$ kubectl patch svc/kubernetes-dashboard -n kubernetes-dashboard --patch "$(cat k8s-dashboard-patch.yaml)"
service/kubernetes-dashboard patched
We can check that it is applied and accesible:
$ kubectl get svc/kubernetes-dashboard -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes-dashboard NodePort 10.111.5.45 <none> 80:31001/TCP 1m
$ curl http://$(minikube ip):31001
<!--
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
...
...
NGINX Config to proxy NodePorts¶
Using the previous example with the Dashboard using a NodePort, we can expose the Dashboard in the Host machinein a http://localhost/minikube
path or http://<host_ip>/minikube
by using NGINX.
Installing NGINX:
sudo apt install nginx
Starting NGINX:
sudo systemctl start nginx
Creating our basic proxy configuration at /etc/nginx/sites-available/minikube
:
cat - <<EOF | sudo tee /etc/nginx/sites-available/minikube
server {
listen 80;
location /minikube/ {
proxy_pass http://$(minikube ip):31001/;
}
}
EOF
And now we need to enable the site in NGINX by creating a link to /etc/nginx/sites-enabled/
:
sudo ln -s /etc/nginx/sites-available/minikube /etc/nginx/sites-enabled/minikube
And reload the config:
sudo systemctl reload nginx
By now we should be able to access Minkube K8s Dashboard from the host or from the outside pointing to the host IP:
curl http://localhost/minikube/
<!--
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
...
...