Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shawnbutts/e9f8275aa13c406f21374ed240955b98 to your computer and use it in GitHub Desktop.
Save shawnbutts/e9f8275aa13c406f21374ed240955b98 to your computer and use it in GitHub Desktop.
Local Kubernetes setup on macOS with minikube on VirtualBox

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!

Prerequisites

  • kubectl
  • docker (for Mac)
  • minikube
  • virtualbox
brew update && 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 my-app.yml

You should now see your pod and your service:

kubectl get all

The configuration exposes my-app outside of the cluster, you can get the address to access it by running:

minikube service my-app --url

This should give an output like http://192.168.99.100:30304 (the port will most likely differ).

Kubernetes GUI

Get the IP:

kubectl describe nodes | grep Addresses

Get the port:

kubectl get svc kubernetes-dashboard -o json --namespace=kube-system | grep nodePort

Then go to http://<IP>:<PORT>.

Reset everything

minikube stop;
minikube delete;
rm -rf ~/.minikube .kube;
brew uninstall kubectl;
brew cask uninstall docker virtualbox minikube;

TODO

Will try to convert this to xhyve when possible.

# APP DEPLOYMENT
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
run: my-app
name: my-app
spec:
replicas: 1
selector:
matchLabels:
run: my-app
template:
metadata:
labels:
run: my-app
spec:
containers:
- image: localhost:5000/my-app:0.0.1
name: my-app
ports:
- containerPort: 80
protocol: TCP
---
# APP SERVICE
apiVersion: v1
kind: Service
metadata:
labels:
run: my-app
name: my-app
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: app-frontend
type: NodePort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment