# -*- mode: ruby -*- # vi: set ft=ruby : require 'securerandom' # ----------------------------------------------------------------------------- # Install local Kubernetes cluster # ----------------------------------------------------------------------------- # # - K8s nodes: 1 master and 2 workers, hostnames: host[0-2] # - Boxes: VirtualBox VM's, 2GB RAM, Ubuntu OS # # Usage: 1) git clone # 2) vagrant up # 3) vagrant ssh host0, run kubectl, ... etc # 4) shared dir gets mounted as '/vagrant' (token file, admin.conf) # 5) for multiple k8s versions use 'kubevg.bat' # # Changes: See CHANGES.md # # Original source: https://github.com/grahamdaley/vagrant-kubernetes (k8s v1.6?) # Updated version: https://github.com/mkorthof/vagrant-kubernetes (k8s v1.18) # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Configuration # ----------------------------------------------------------------------------- # Usually leaving these options as-is should be fine # Vagrant options # ############### # - Where it says "node(s)" that means the VM(s) it runs on as well # - Use *1* master node for now e.g. $MASTER_NODES = 1 # - Enable dns proxy if you're behind NAT and having DNS issues with VirtualBox $VG_BOX = "ubuntu/xenial64" # vagrant box $MASTER_NODES = 1 # nr of master node(s) $WORKER_NODES = 2 # nr of worker node(s) $TOKEN_FILE = ".cluster_token" # token for kubeadm init $IP_PREFIX = "192.168.33" # set node ip(s) to <1.2.3>.{10+i} $IP_RANDOM = 0 # [0/1] use random prefix in 192.168.33.0/17 $KUBEADM_INIT = "yaml" # [flags|yaml] kubeadm init config method $VB_FWD_PROXY = 1 # [0/1] forward proxy port (8001) $VB_DNSPROXY_NAT = 0 # [0/1] enable nat dns proxy in vbox # Kubernetes options # ################## # - Best leave OS_DIST at "xenial", even for newer Ubuntu dist versions like 20.04+ # - Docker support: https://kubernetes.io/docs/setup/production-environment/container-runtimes # ( Removed options for older k8s versions: $K8S_KUBEPROXY_CFIX, $K8S_KUBEPROXY_UFIX ) $K8S_VERSION = "1.18.5" # kubernetes version for apt packages $K8S_OS_DIST = "xenial" # kubernetes os dist for apt packages $K8S_RUNTIME = "docker-ce" # [docker.io|docker-ce] container runtime $K8S_NODE_IP = 1 # [0/1] set kubelet node_ip to VM IPS $K8S_API_STATIC_ROUTE = 0 # [0/1] set static route to cluster-api ip (weave) $DOCKER_VERSION = "5:19.03.11~3-0~ubuntu-xenial" # use verified version (k8s release notes) $K8S_ADMIN_CONF = "/etc/kubernetes/admin.conf" # leave as-is, will be copied to /vagrant # Kubernetes Addons # ################# $K8S_NETWORKING = "calico" # [weave|flannel|calico] network addon $K8S_NETWORKING_RBAC = 0 # [0/1] rbac authorization $K8S_NETWORKING_CALICOCTL = 1 # [0/1] deploy calicoctl pod $K8S_DASHBOARD = 1 # [0/1] kubernetes dashboard $K8S_METRICS_SERVER = 0 # [0/1] metrics-server $K8S_NGINX = 0 # [0/1] nginx ingress $K8S_METALLB = 0 # [0/1] metallb loadbalacner $K8S_DNSUTILS = 1 # [0/1] dnsutils example pod in default namespace $K8S_BUSYBOX = 1 # [0/1] busybox example pod in default namespace $K8S_HELLOWORLD = 1 # [0/1] hello-world example, needs ingress $K8S_DASH_TOKEN = "dashboard-token.txt" # file in /vagrant with dashboard token to login $K8S_DASH_LINK = "Dashboard.html" # file in /vagrant with link to dashboard # Network IP ranges (RFC 1918) # ############################# # - Available blocks: "192.168.0.0/16", "10.0.0.0/8" or "172.16.0.0/12" # - Do *not* overlap physical and/or overlay networks # - Cluster CIDR is controlled by network plugin with K8S_PODNET_CIDR_CALICO # - IP Pool in CALICO_IPV4POOL_CIDR should fall within 'cluster-cidr' # - https://www.projectcalico.org/calico-ipam-explained-and-enhanced/ $K8S_SERVICE_CIDR = "10.96.0.0/12" # default k8s service cidr $K8S_PODNET_CIDR_FLANEL = "10.96.0.0/12" # default flannel pods cidr $K8S_PODNET_CIDR_CALICO = "192.168.128.0/17" # tested with physical network "192.168/24" $CALICO_IPV4POOL_CIDR = "192.168.192.0/18" # tested with physical network "192.168/24" # $K8S_PODNET_CIDR_CALICO = "192.168.0.0/16" # uncomment for default calico pods cidr # $CALICO_IPV4POOL_CIDR = "192.168.0.0/18" # uncomment for default calico pool cidr # Or, uncomment settings below to prevent *any* overlap with "192.168.0.0/16" # $K8S_PODNET_CIDR_FLANEL = "10.244.0.0/16" # $K8S_PODNET_CIDR_CALICO = "172.16.0.0/12" # $CALICO_IPV4POOL_CIDR = "172. 0.0/16" # ----------------------------------------------------------------------------- # END OF CONFIG # ----------------------------------------------------------------------------- $K8S_DEBUG = 0 # [1|255] Set 1 to enable, 255 dumps vars and exits provisioning script $K8S_FAKEVER = 0 if not ENV['K8S_VERSION'].nil? $K8S_VERSION=ENV['K8S_VERSION'] # kubevb.bat also handles this if not Dir.exist?('../' + $K8S_VERSION) then puts 'ERROR: Dir ' + $K8S_VERSION + ' does not exist' exit 1 end end if ($K8S_DEBUG == 255 && $K8S_FAKEVER == 1) then $K8S_VERSION = "0.0-0" end # Debug Vagrant # ############# # - SET VAGRANT_LOG=info # - vagrant up --debug # - vagrant up --debug 2>&1 | Tee-Object -FilePath ".\vagrant.log" # ----------------------------------------------------------------------------- # COMMON SETUP METHOD # ----------------------------------------------------------------------------- def common_setup_script() script = <