Skip to content

Instantly share code, notes, and snippets.

@davidalger
Forked from kevin-smets/1_kubernetes_on_macOS.md
Created September 18, 2018 17:59
Show Gist options
  • Select an option

  • Save davidalger/24e7a7a2f15790933a2935d7c741128f to your computer and use it in GitHub Desktop.

Select an option

Save davidalger/24e7a7a2f15790933a2935d7c741128f to your computer and use it in GitHub Desktop.
Local Kubernetes setup on macOS with minikube on VirtualBox and local Docker registry

Requirements

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:

sysctl -a | grep machdep.cpu.features | grep VMX

If there's output, you're good!

Install all the things

Everything works on Docker for Mac now, so run the following:

brew install kubectl; brew cask install docker minikube virtualbox

Verify

docker --version                # Docker version 1.12.3, build 6b644ec
docker-compose --version        # docker-machine version 0.8.2, build e18a919
docker-machine --version        # docker-compose version 1.8.1, build 878cff1
minikube version                # minikube version: v0.12.2
kubectl version --client        # Client Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.6+e569a27", GitCommit:"e569a27d02001e343cb68086bc06d47804f62af6", GitTreeState:"not a git tree", BuildDate:"2016-11-12T09:26:56Z", GoVersion:"go1.7.3", Compiler:"gc", Platform:"darwin/amd64"}      

Start

minikube start

This can take a while, expected output:

Starting local Kubernetes cluster...
Kubectl is now configured to use the cluster.

Great! You now have a running Kubernetes cluster locally. Minikube started a virtual machine for you, and a Kubernetes cluster is now running in that VM.

Check k8s

kubectl get nodes

Should output something like:

NAME       STATUS    AGE
minikube   Ready     8m

Use minikube's built-in docker daemon:

eval $(minikube docker-env)

Running docker ps should now output something like:

CONTAINER ID        IMAGE                                                        COMMAND                  CREATED             STATUS              PORTS               NAMES
474eae7e7dd4        gcr.io/google_containers/kubernetes-dashboard-amd64:v1.4.0   "/dashboard --port=90"   35 minutes ago      Up 35 minutes                           k8s_kubernetes-dashboard.bdfedaad_kubernetes-dashboard-46007_kube-system_92b679ab-982b-11e6-8ad0-c604d62c2a3b_2afa3feb
6142f91d57ab        gcr.io/google_containers/pause-amd64:3.0                     "/pause"                 35 minutes ago      Up 35 minutes                           k8s_POD.2225036b_kubernetes-dashboard-46007_kube-system_92b679ab-982b-11e6-8ad0-c604d62c2a3b_61445f01
332c645bb167        gcr.io/google-containers/kube-addon-manager:v5.1             "/opt/kube-addons.sh"    35 minutes ago      Up 35 minutes                           k8s_kube-addon-manager.92e38b3b_kube-addon-manager-minikube_kube-system_46ae05e07c52d84167b077b142aa4a39_253f9280
8ea2cd68e0a8        gcr.io/google_containers/pause-amd64:3.0                     "/pause"                 35 minutes ago      Up 35 minutes                           k8s_POD.d8dbe16c_kube-addon-manager-minikube_kube-system_46ae05e07c52d84167b077b142aa4a39_da8bd6f9

Deploy and run an image on your local k8s setup

First setup a local registry, so Kubernetes can pull the image(s) from there:

docker run -d -p 5000:5000 --restart=always --name registry registry:2

If you have already built an image, e.g. named 'my-app' locally (check by using docker images), you can publish it to your local repo:

docker tag my-app localhost:5000/my-app

Check the two yaml files, and run the following:

kubectl create -f app-deployment.yml
kubectl create -f app-service.yml

You should now see your pods:

kubectl get pods

Reset everything

minikube stop;
rm -rf ~/.minikube .kube;
brew uninstall kubectl;
brew cask uninstall docker virtualbox minikube;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment