This branch is using MicroK8s and NFS as storage provider. Check other branches for other providers.
Starting up a Kubernetes cluster with Vagrant and VirtualBox.
vagrant box update # can fail safely
vagrant up
# Now you can login
vagrant ssh
# You are no able to play with kubectl, docker, helm
kubectl get pods
Created nodes are k8s01 (master), k8s02 and so on (depends on NODES and PREFIX variables). Kubernetes Dashboard with admin rigths is available at http://192.168.60.100:8001/
Cluster can merly be stopped by issuing vagrant halt
and later restarted with vagrant up
(with same env vars!).
PersistentVolumeClaims are provisionned by NFS using default storage class "nfs-csi". Actual storage is located on the first VM (k8s01) on /srv/nfs. Check other branches to chage storage provider.
Ingresses are served by Traefik on port 80. The traefik dashboard is available at http://192.168.60.100:9500/.
Invoke kubectl apply -f https://raw.githubusercontent.com/fondemen/vagrant-kubernetes/microk8s/nginx-test-file.yml
. Within the next minute, you should find a nginx.local/
router associated to a servce with two backends. curl -H 'Host: nginx.local' 192.168.60.100
should return a 403 (as no file exists to be served).
To load a file, mkdir nginx-data; sudo mount -t nfs 192.168.60.100:/srv/nfs/$(kubectl get pvc test-pvc -o jsonpath='{.spec.volumeName}') nginx-data
to mount the NFS volume. Add an index.html
file to nginx-data
, unmount the volume by running sudo umount nginx-data
and then curl -H 'Host: nginx.local' 192.168.60.100
should serve you that file.
Dashboards (Kubernetes and Traefik) can be exposed unsecured on the host machine by setting the EXPOSE_DB_PORTS env var to true before firing up the vagrant up
or another vagrant provision
in case the cluster already exists.
Configuration is performed using environment variables:
Changes default values for some of the following environment variables (such as BOX or TRAEFIK) so that they match latest available dedicated image. State true
or 1
to enable.
Default is false.
The channel of MicroK8s to install. Check . Setting this to 0
or false
disables kubernetes installation.
Default is latest/stable.
The port at which exposing the Kubernetes Dashboard. Traefik must be enabled for the dashboard to be visible. Set to 0 to disable. Default is 8001.
Coma-separated list of registries that can be accessed insecurely. Ex: LOCAL_INSECURE_REGISTRIES
. Default is ''.
The version of Traefik to install. Check tags on Docker Hub. Set to latest to get the latest version. Default is latest.
The port at which exposing the Traefik dashoard. Set to 0 to disable. Default is 9500.
The number of nodes in the cluster (including master). Default is 2.
The memory used by each worker VM (in MB) Default is 2048.
The number of CPUs for worker nodes Default is 1.
The memory used by the master VM (in MB) Default is 2048.
The number of CPUs for the master node Default is 2.
The public key used for pasphraseless ssh between node. It's the same key for each node. Should be synchronized with PRIVATE_ROOT_KEY. You're encouraged to change the default value.
The private key used for pasphraseless ssh between node. Should be synchronized with PUBLIC_ROOT_KEY. It's the same key for each node. You're encouraged to change the default value.
The image to use. It must be Debian-based. So far, only tested with bento/debian-10 and its fork fondement/k8s. Default is fondement/k8s.
The url of the image to use. It must be consistent with BOX. Default is false.
The name prefix for VMs. The final VM name is the prefix followed by VM number using 2 digits. Default value is k8s.
The IP of the first node (e.g. k8s01), that is the master node. Other nodes have the same IP their node number -1, e.g. if node 0 is 192.168.60.100, then node 3 is 192.168.60.102. Default value is 192.168.60.100.
Whether to check for VirtualBox guest additions. Default is false.
Whether to upgrade OS. In case OS is actually upgraded, restart cluster with vagrant halt;vagrant up
.
Default is false.
Whether to install the vagrant-scp plugin. Default is true.