Enable nested virtualization on an instance

https://cloud.google.com/compute/docs/instances/enable-nested-virtualization-vm-instances

Create a boot disk.

gcloud compute disks create disk1 --image-project centos-cloud --image-family centos-7 --zone us-central1-a

Create image with License.

Note: This may take a minute.

gcloud compute images create nested-vm-image --source-disk=disk1 --source-disk-zone=us-central1-a --licenses=https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx

Delete source disk, as it is no longer needed.

gcloud compute disks delete disk1 --zone us-central1-a

Create Instance

Before you create your instance, you need to check if your zone currently has the minimum CPU platform (Intel Haswell or newer) requirement.

https://cloud.google.com/compute/docs/cpu-platforms

gcloud compute zones describe [ZONE]

Example

gcloud compute zones describe us-central1-a
availableCpuPlatforms:
- Intel Cascade Lake
- Intel Skylake
- Intel Broadwell
- Intel Haswell
- Intel Sandy Bridge

Create instance.

gcloud compute instances create example-nested-vm --zone us-central1-a \
   --min-cpu-platform "Intel Haswell" \
   --machine-type n1-standard-4 \
   --image nested-vm-image

SSH into vm.

gcloud compute ssh example-nested-vm --zone us-central1-a

Confirm nested virtualization is enabled (should return 1).

grep -cw vmx /proc/cpuinfo

Example

grep -cw vmx /proc/cpuinfo
1

Install kubectl

{
  curl -LO https://storage.googleapis.com/kubernetes-release/release/curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt/bin/linux/amd64/kubectl
  chmod +x ./kubectl
  sudo mv ./kubectl /usr/local/bin/kubectl
}

Install VirtualBox

{
sudo yum install kernel-devel kernel-headers make patch gcc wget
sudo wget https://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo -P /etc/yum.repos.d
sudo yum install VirtualBox-6.0
}

Verify VirtualBox is installed.

systemctl status vboxdrv

Install Minikube

{
  curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
  sudo cp minikube /usr/bin/
}

Install docker

sudo yum install docker

Start Minikube

minikube start

Example

minikube start
😄  minikube v1.3.1 on Centos 7.6.1810
🔥  Creating virtualbox VM (CPUs=2, Memory=2000MB, Disk=20000MB) …
🐳  Preparing Kubernetes v1.15.2 on Docker 18.09.8 …
💾  Downloading kubelet v1.15.2
💾  Downloading kubeadm v1.15.2
🚜  Pulling images …
🚀  Launching Kubernetes …
⌛  Waiting for: apiserver proxy etcd scheduler controller dns
🏄  Done! kubectl is now configured to use "minikube"

Verify Cluster.

kubectl cluster-info

Example

kubectl cluster-info
Kubernetes master is running at https://192.168.99.101:8443
KubeDNS is running at https://192.168.99.101:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.