{"id":3005,"date":"2017-12-23T10:58:32","date_gmt":"2017-12-23T02:58:32","guid":{"rendered":"http:\/\/switch.linesno.com\/?p=3005"},"modified":"2017-12-23T10:58:51","modified_gmt":"2017-12-23T02:58:51","slug":"kubernetes_on_macos","status":"publish","type":"post","link":"http:\/\/switch.linesno.com\/?p=3005","title":{"rendered":"kubernetes_on_macOS"},"content":{"rendered":"<h1>Requirements<\/h1>\n<p>Minikube requires that VT-x\/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX \/ macOS run:<\/p>\n<pre><code>sysctl -a | grep machdep.cpu.features | grep VMX\r\n<\/code><\/pre>\n<p>If there&#8217;s output, you&#8217;re good!<\/p>\n<h1><a id=\"user-content-prerequisites\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#prerequisites\" aria-hidden=\"true\"><\/a>Prerequisites<\/h1>\n<ul>\n<li>kubectl<\/li>\n<li>docker (for Mac)<\/li>\n<li>minikube<\/li>\n<li>virtualbox<\/li>\n<\/ul>\n<pre><code>brew update &amp;&amp; brew install kubectl &amp;&amp; brew cask install docker minikube virtualbox\r\n<\/code><\/pre>\n<h1><a id=\"user-content-verify\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#verify\" aria-hidden=\"true\"><\/a>Verify<\/h1>\n<pre><code>docker --version                # Docker version 17.09.0-ce, build afdb6d4\r\ndocker-compose --version        # docker-compose version 1.16.1, build 6d1ac21\r\ndocker-machine --version        # docker-machine version 0.12.2, build 9371605\r\nminikube version                # minikube version: v0.22.3\r\nkubectl 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\"}      \r\n<\/code><\/pre>\n<h1><a id=\"user-content-start\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#start\" aria-hidden=\"true\"><\/a>Start<\/h1>\n<pre><code>minikube start\r\n<\/code><\/pre>\n<p>This can take a while, expected output:<\/p>\n<pre><code>Starting local Kubernetes cluster...\r\nKubectl is now configured to use the cluster.\r\n<\/code><\/pre>\n<p>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.<\/p>\n<h1><a id=\"user-content-check-k8s\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#check-k8s\" aria-hidden=\"true\"><\/a>Check k8s<\/h1>\n<pre><code>kubectl get nodes\r\n<\/code><\/pre>\n<p>Should output something like:<\/p>\n<pre><code>NAME       STATUS    ROLES     AGE       VERSION\r\nminikube   Ready     &lt;none&gt;    40s       v1.7.5\r\n<\/code><\/pre>\n<h1><a id=\"user-content-use-minikubes-built-in-docker-daemon\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#use-minikubes-built-in-docker-daemon\" aria-hidden=\"true\"><\/a>Use minikube&#8217;s built-in docker daemon:<\/h1>\n<pre><code>eval $(minikube docker-env)\r\n<\/code><\/pre>\n<p>Running\u00a0<code>docker ps<\/code>\u00a0should now output something like:<\/p>\n<pre><code>CONTAINER ID        IMAGE                                         COMMAND                 CREATED             STATUS              PORTS               NAMES\r\ne97128790bf9        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\r\n69707e54d1d0        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\r\n<\/code><\/pre>\n<h1><a id=\"user-content-build-deploy-and-run-an-image-on-your-local-k8s-setup\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#build-deploy-and-run-an-image-on-your-local-k8s-setup\" aria-hidden=\"true\"><\/a>Build, deploy and run an image on your local k8s setup<\/h1>\n<p>First setup a local registry, so Kubernetes can pull the image(s) from there:<\/p>\n<pre><code>docker run -d -p 5000:5000 --restart=always --name registry registry:2\r\n<\/code><\/pre>\n<h2><a id=\"user-content-build\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#build\" aria-hidden=\"true\"><\/a>Build<\/h2>\n<p>First of, store all files (Dockerfile, my-app.yml, index.html) in this gist locally in some new (empty) directory.<\/p>\n<p>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:<\/p>\n<pre><code>docker build . --tag my-app\r\n<\/code><\/pre>\n<p>You should now have an image named &#8216;my-app&#8217; locally, check by using\u00a0<code>docker images<\/code>\u00a0(or your own image of course). You can then publish it to your local docker registry:<\/p>\n<pre><code>docker tag my-app localhost:5000\/my-app:0.1.0\r\n<\/code><\/pre>\n<p>Running\u00a0<code>docker images<\/code>\u00a0should now output the following:<\/p>\n<pre><code>REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE\r\nmy-app                                                 latest              cc949ad8c8d3        44 seconds ago      89.3MB\r\nlocalhost:5000\/my-app                                  0.1.0               cc949ad8c8d3        44 seconds ago      89.3MB\r\nhttpd                                                  2.4-alpine          fe26194c0b94        7 days ago          89.3MB\r\n<\/code><\/pre>\n<h2><a id=\"user-content-deploy-and-run\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#deploy-and-run\" aria-hidden=\"true\"><\/a>Deploy and run<\/h2>\n<p>Store the file below\u00a0<code>my-app.yml<\/code>\u00a0on your system and run the following:<\/p>\n<pre><code>kubectl create -f my-app.yml\r\n<\/code><\/pre>\n<p>You should now see your pod and your service:<\/p>\n<pre><code>kubectl get all\r\n<\/code><\/pre>\n<p>The configuration exposes\u00a0<code>my-app<\/code>\u00a0outside of the cluster, you can get the address to access it by running:<\/p>\n<pre><code>minikube service my-app --url\r\n<\/code><\/pre>\n<p>This should give an output like\u00a0<code>http:\/\/192.168.99.100:30304<\/code>\u00a0(the port will most likely differ). Go there with your favorite browser, you should see &#8220;Hello world!&#8221;. You just accessed your application from outside of your local Kubernetes cluster!<\/p>\n<h1><a id=\"user-content-kubernetes-gui\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#kubernetes-gui\" aria-hidden=\"true\"><\/a>Kubernetes GUI<\/h1>\n<pre><code>minikube dashboard\r\n<\/code><\/pre>\n<h1><a id=\"user-content-delete-deployment-of-my-app\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#delete-deployment-of-my-app\" aria-hidden=\"true\"><\/a>Delete deployment of my-app<\/h1>\n<pre><code>kubectl delete deploy my-app\r\nkubectl delete service my-app\r\n<\/code><\/pre>\n<p>You&#8217;re now good to go and deploy other images!<\/p>\n<h1><a id=\"user-content-reset-everything\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#reset-everything\" aria-hidden=\"true\"><\/a>Reset everything<\/h1>\n<pre><code>minikube stop;\r\nminikube delete;\r\nrm -rf ~\/.minikube .kube;\r\nbrew uninstall kubectl;\r\nbrew cask uninstall docker virtualbox minikube;\r\n<\/code><\/pre>\n<h1><a id=\"user-content-todo\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#todo\" aria-hidden=\"true\"><\/a>TODO<\/h1>\n<p>Will try to convert this to xhyve when possible.<\/p>\n<h1><a id=\"user-content-version\" class=\"anchor\" href=\"https:\/\/gist.github.com\/kevin-smets\/b91a34cea662d0c523968472a81788f7#version\" aria-hidden=\"true\"><\/a>Version<\/h1>\n<p>Last tested on 2017 October 20th macOS Sierra 10.12.6<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirements Minikube requires that VT-x\/AMD-v virtuali [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86],"tags":[88],"class_list":["post-3005","post","type-post","status-publish","format-standard","hentry","category-service","tag-88"],"_links":{"self":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/3005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3005"}],"version-history":[{"count":1,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/3005\/revisions"}],"predecessor-version":[{"id":3006,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/3005\/revisions\/3006"}],"wp:attachment":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3005"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}