|
| 1 | +# Requirements |
| 2 | + |
| 3 | +Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run: |
| 4 | + |
| 5 | + sysctl -a | grep machdep.cpu.features | grep VMX |
| 6 | + |
| 7 | +If there's output, you're good! |
| 8 | + |
| 9 | +# Prerequisites |
| 10 | + |
| 11 | +- kubectl |
| 12 | +- docker (for Mac) |
| 13 | +- minikube |
| 14 | +- virtualbox |
| 15 | + |
| 16 | +``` |
| 17 | +brew update && brew install kubectl && brew cask install docker minikube virtualbox |
| 18 | +``` |
| 19 | + |
| 20 | +# Verify |
| 21 | + |
| 22 | + docker --version # Docker version 17.09.0-ce, build afdb6d4 |
| 23 | + docker-compose --version # docker-compose version 1.16.1, build 6d1ac21 |
| 24 | + docker-machine --version # docker-machine version 0.12.2, build 9371605 |
| 25 | + minikube version # minikube version: v0.22.3 |
| 26 | + kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} |
| 27 | + |
| 28 | +# Start |
| 29 | + |
| 30 | + minikube start |
| 31 | + |
| 32 | +This can take a while, expected output: |
| 33 | + |
| 34 | + Starting local Kubernetes cluster... |
| 35 | + Kubectl is now configured to use the cluster. |
| 36 | + |
| 37 | +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. |
| 38 | + |
| 39 | +# Check k8s |
| 40 | + |
| 41 | + kubectl get nodes |
| 42 | + |
| 43 | +Should output something like: |
| 44 | + |
| 45 | + NAME STATUS ROLES AGE VERSION |
| 46 | + minikube Ready <none> 40s v1.7.5 |
| 47 | + |
| 48 | +# Use minikube's built-in docker daemon: |
| 49 | + |
| 50 | + eval $(minikube docker-env) |
| 51 | + |
| 52 | +Running `docker ps` should now output something like: |
| 53 | + |
| 54 | +``` |
| 55 | +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 56 | +e97128790bf9 gcr.io/google-containers/kube-addon-manager "/opt/kube-addons.sh" 22 seconds ago Up 22 seconds k8s_kube-addon-manager_kube-addon-manager-minikube_kube-system_c654b2f084cf26941c334a2c3d6db53d_0 |
| 57 | +69707e54d1d0 gcr.io/google_containers/pause-amd64:3.0 "/pause" 33 seconds ago Up 33 seconds k8s_POD_kube-addon-manager-minikube_kube-system_c654b2f084cf26941c334a2c3d6db53d_0 |
| 58 | +``` |
| 59 | + |
| 60 | +# Build, deploy and run an image on your local k8s setup |
| 61 | + |
| 62 | +First setup a local registry, so Kubernetes can pull the image(s) from there: |
| 63 | + |
| 64 | + docker run -d -p 5000:5000 --restart=always --name registry registry:2 |
| 65 | + |
| 66 | +## Build |
| 67 | + |
| 68 | +First of, store all files (Dockerfile, my-app.yml, index.html) in this gist locally in some new (empty) directory. |
| 69 | + |
| 70 | +You can build the Dockerfile below locally if you want to follow this guide to the letter. Store the Dockerfile locally, preferably in an empty directory and run: |
| 71 | + |
| 72 | + docker build . --tag my-app |
| 73 | + |
| 74 | +You should now have an image named 'my-app' locally, check by using `docker images` (or your own image of course). You can then publish it to your local docker registry: |
| 75 | + |
| 76 | + docker tag my-app localhost:5000/my-app:0.1.0 |
| 77 | + |
| 78 | +Running `docker images` should now output the following: |
| 79 | + |
| 80 | +``` |
| 81 | +REPOSITORY TAG IMAGE ID CREATED SIZE |
| 82 | +my-app latest cc949ad8c8d3 44 seconds ago 89.3MB |
| 83 | +localhost:5000/my-app 0.1.0 cc949ad8c8d3 44 seconds ago 89.3MB |
| 84 | +httpd 2.4-alpine fe26194c0b94 7 days ago 89.3MB |
| 85 | +``` |
| 86 | + |
| 87 | +## Deploy and run |
| 88 | + |
| 89 | +Store the file below `my-app.yml` on your system and run the following: |
| 90 | + |
| 91 | + kubectl create -f my-app.yml |
| 92 | + |
| 93 | +You should now see your pod and your service: |
| 94 | + |
| 95 | + kubectl get all |
| 96 | + |
| 97 | +The configuration exposes `my-app` outside of the cluster, you can get the address to access it by running: |
| 98 | + |
| 99 | + minikube service my-app --url |
| 100 | + |
| 101 | +This should give an output like `http://192.168.99.100:30304` (the port will most likely differ). Go there with your favorite browser, you should see "Hello world!". You just accessed your application from outside of your local Kubernetes cluster! |
| 102 | + |
| 103 | +# Kubernetes GUI |
| 104 | + |
| 105 | + minikube dashboard |
| 106 | + |
| 107 | +# Delete deployment of my-app |
| 108 | + |
| 109 | + kubectl delete deploy my-app |
| 110 | + kubectl delete service my-app |
| 111 | + |
| 112 | +You're now good to go and deploy other images! |
| 113 | + |
| 114 | +# Reset everything |
| 115 | + |
| 116 | + minikube stop; |
| 117 | + minikube delete; |
| 118 | + rm -rf ~/.minikube .kube; |
| 119 | + brew uninstall kubectl; |
| 120 | + brew cask uninstall docker virtualbox minikube; |
| 121 | + |
| 122 | +# Version |
| 123 | + |
| 124 | +Last tested on 2017 October 20th |
| 125 | +macOS Sierra 10.12.6 |
0 commit comments