{"id":352,"date":"2018-10-16T10:52:50","date_gmt":"2018-10-16T10:52:50","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw93\/?p=352"},"modified":"2018-10-17T08:26:07","modified_gmt":"2018-10-17T08:26:07","slug":"docker-for-mac-with-kubernetes-support","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw93\/index.php\/2018\/10\/16\/docker-for-mac-with-kubernetes-support\/","title":{"rendered":"Docker for Mac with Kubernetes support"},"content":{"rendered":"<p>Jan 29, 2018<\/p>\n<p>by <a href=\"https:\/\/container-solutions.com\/author\/catalin\/\">Catalin Jora<\/a><\/p>\n<p>During <a href=\"https:\/\/europe-2017.dockercon.com\/\">DockerCon Copenhagen<\/a>, Docker announced support and integration for Kubernetes, alongside Swarm. The first integration is in the Docker for Mac, where you can run now a 1 node Kubernetes cluster. This allows you to deploy apps with Docker-compose files to that local Kubernetes cluster via the docker cli. In this blogpost, I\u2019ll cover what you need to know about this integration and how to make the most out of it.<\/p>\n<p>While a lot of computing workload moves to the cloud, the local environment is still relevant. This is the first place where software is built, executed and where (unit) tests run. Docker, helped us to get rid of the famous \u201cit works on my machine\u201d by automating the repetitive and error-prone tasks. But unless you\u2019re into building \u201chello world\u201d apps, you\u2019ll have to manage the lifecycle of a bunch of containers that need to work together. Thus, you\u2019ll need management for your running containers, commonly called nowadays orchestration.<\/p>\n<p>All major software orchestration platforms have their own \u201cmini\u201d distribution that can run on a developer machine. If you work with Mesos you have <a href=\"https:\/\/minimesos.org\/\">minimesos<\/a> (container based), for Kubernetes there is <a href=\"https:\/\/github.com\/kubernetes\/minikube\">minikube<\/a> (virtual machine). RedHat offers both a virtual machine (<a href=\"https:\/\/www.openshift.org\/minishift\/\">minishift<\/a>) and a container based tool (<a href=\"https:\/\/docs.openshift.org\/latest\/cli_reference\/get_started_cli.html\">oc<\/a> cli) for their K8s distribution (Openshift). Docker has <a href=\"https:\/\/docs.docker.com\/compose\/\">compose<\/a>, <a href=\"https:\/\/docs.docker.com\/engine\/swarm\/\">swarm-mode<\/a> orchestration and since recently also supports <a href=\"https:\/\/www.docker.com\/kubernetes\">Kubernetes<\/a> (for now only in Docker for Mac).<\/p>\n<p>If you\u2019re new to Kubernetes you\u2019ll wanna familiarize with the basic concepts using this <a href=\"https:\/\/kubernetes.io\/docs\/tutorials\/kubernetes-basics\/\">official Kubernetes tutorial<\/a> we build together with Google, <a href=\"https:\/\/twitter.com\/rmbrtoplay\">Remembertoplay<\/a> and <a href=\"https:\/\/twitter.com\/teamKatacoda\">Katacoda<\/a>.<\/p>\n<p>Enabling Kubernetes in Docker for Mac, will install a containerized distribution of Kubernetes and it\u2019s cli (<a href=\"https:\/\/kubernetes.io\/docs\/reference\/generated\/kubectl\/kubectl\/\">kubectl<\/a>), which will allow you to interact with the cluster. On resource level, the new cluster will use whatever Docker for Mac has available for use.<\/p>\n<p>The release is in beta (at the time of writing the article) and available via the Docker Edge channel. Once you\u2019re logged in with your Docker account, you can enable Kubernetes via the dedicated menu from the UI:<\/p>\n<p><a href=\"http:\/\/container-solutions.com\/content\/uploads\/2018\/01\/kubernetes-docker-mac.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/container-solutions.com\/content\/uploads\/2018\/01\/kubernetes-docker-mac.png\" alt=\"kubernetes docker mac\" width=\"990\" height=\"636\" \/><\/a><\/p>\n<p>At this point, if you never connected to a Kubernetes cluster on your Mac, you\u2019re good to go. Kubectl will point to the new (and only) configured cluster. If this is not the case, you\u2019ll need to point kubectl to the right cluster. Docker for Mac will not change your default Kubernetes context. You\u2019ll need to manually switch the context to \u2018docker-for-desktop\u2019:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>kubectl config get-contexts<\/p>\n<p>CURRENT NAME CLUSTER AUTHINFO NAMESPACE<\/p>\n<p>&#8230;<\/p>\n<p>docker-for-desktop docker-for-desktop-cluster docker-for-desktop<\/p>\n<p>* minikube minikube minikube<\/p>\n<p>&#8230;<\/p>\n<p>kubectl config use-context docker-for-desktop<\/p>\n<p>Switched to context &#8220;docker-for-desktop&#8221;.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Going to kubectl utility now, you should be able to run commands towards the new cluster:<\/p>\n<table style=\"font-size: 1rem;\">\n<tbody>\n<tr>\n<td><\/td>\n<td>kubectl cluster-info<\/p>\n<p>Kubernetes master is running at https:\/\/localhost:6443<\/p>\n<p>KubeDNS is running at https:\/\/localhost:6443\/api\/v1\/namespaces\/kube-system\/services\/kube-dns\/proxy<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em>Note: You may have already another kubectl installed on your machine (E.g. installed via gcloud utility if you used GKE before, or as a stand-alone program if you used minikube). Docker will install automatically a new kubectl binary in \/usr\/local\/bin\/. You\u2019ll need to decide which one you\u2019ll keep.<\/em><\/p>\n<p>Ok, let\u2019s try to install our first apps using a Docker-compose file. Yes, the previous sentence is correct. If you want to deploy apps to your new local Kubernetes cluster using the docker cli, docker-compose file is the only way. If you already have some Kubernetes manifests you plan to deploy, you can do it using the known way, with kubectl.<\/p>\n<p>We\u2019re using here the demo-app from the official docker-page about Kubernetes:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>wget https:\/\/raw.githubusercontent.com\/jocatalin\/k8s-docker-mac\/master\/docker-compose.yaml<\/p>\n<p>docker stack deploy -c docker-compose.yaml hello-k8s-from-docker<\/p>\n<p>Stack hello-k8s-from-docker was updated<\/p>\n<p>Waiting for the stack to be stable and running&#8230;<\/p>\n<p>&#8211; Service db has one container running<\/p>\n<p>&#8211; Service words has one container running<\/p>\n<p>&#8211; Service web has one container running<\/p>\n<p>Stack hello-k8s-from-docker is stable and running<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If you\u2019re familiar with Docker swarm, there is nothing new about the command. What\u2019s different is that the stack was deployed to our new Kubernetes cluster. The command generated deployments, replica sets, pods and services for the 3 applications defined in the compose file:<\/p>\n<table>\n<tbody>\n<tr>\n<td>&nbsp;<\/p>\n<p>1<\/p>\n<p>2<\/p>\n<p>3<\/p>\n<p>4<\/p>\n<p>5<\/p>\n<p>6<\/p>\n<p>7<\/p>\n<p>8<\/p>\n<p>9<\/p>\n<p>10<\/p>\n<p>11<\/p>\n<p>12<\/p>\n<p>13<\/p>\n<p>14<\/p>\n<p>15<\/p>\n<p>16<\/p>\n<p>17<\/p>\n<p>18<\/p>\n<p>19<\/p>\n<p>20<\/p>\n<p>&nbsp;<\/td>\n<td>kubectl get all<\/p>\n<p>NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE<\/p>\n<p>deploy\/db 1 1 1 1 39s<\/p>\n<p>deploy\/web 1 1 1 1 39s<\/p>\n<p>deploy\/words 1 1 1 1 39s<\/p>\n<p>NAME DESIRED CURRENT READY AGE<\/p>\n<p>rs\/db-794c8bc8d9 1 1 1 39s<\/p>\n<p>rs\/web-54cbf7d7fb 1 1 1 39s<\/p>\n<p>rs\/words-575cd67dff 1 1 1 39s<\/p>\n<p>NAME READY STATUS RESTARTS AGE<\/p>\n<p>po\/db-794c8bc8d9-mrw79 1\/1 Running 0 39s<\/p>\n<p>po\/web-54cbf7d7fb-mx4c7 1\/1 Running 0 39s<\/p>\n<p>po\/words-575cd67dff-ddgw2 1\/1 Running 0 39s<\/p>\n<p>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE<\/p>\n<p>svc\/db ClusterIP None 55555\/TCP 39s<\/p>\n<p>svc\/web LoadBalancer 10.96.17.42 80:31420\/TCP 39s<\/p>\n<p>svc\/words ClusterIP None 55555\/TCP 39s<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Doing any change in the docker-compose file and re-deploying it (e.g. change the number of replicas, change the image version) will update the Kubernetes app accordingly. The concept of namespaces is supported as well via the &#8211;namespace parameter. Deleting the application stacks can also be done via the docker cli.<\/p>\n<p>Will Docker for Mac allow you to deploy with the docker cli the compose-files on other Kubernetes cluster? No, it won\u2019t. Trying to deploy the same file on another cluster will return this error:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>could not find compose.docker.com api.<\/p>\n<p>Install it on your cluster first<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The integration is implemented at API level. Open a proxy to the Docker for mac Kubernetes cluster:<\/p>\n<table style=\"font-size: 1rem;\">\n<tbody>\n<tr>\n<td><\/td>\n<td>kubectl proxy<\/p>\n<p>Starting to serve on 127.0.0.1:8001<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Going in the browser to <a href=\"http:\/\/localhost:8001\">http:\/\/localhost:8001<\/a> will reveal some new API\u2019s that are (most probably) responsible for this compose to k8s manifest translation:<\/p>\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>&#8220;\/apis\/compose.docker.com&#8221;<\/p>\n<p>&#8220;\/apis\/compose.docker.com\/v1beta1&#8221;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>So at this point, if you want to deploy the same application stack on other clusters, you need to use something like Kompose to convert docker-compose files to Kubernetes manifests (it didn\u2019t work for my example), or write the manifests by hand.<\/p>\n<p>There are a few advantages here if we\u2019re comparing this implementation with minikube:<\/p>\n<ul>\n<li>If you\u2019re new to Kubernetes, you can deploy and run a local cluster without any other tools or Kubernetes knowledge<\/li>\n<li>You can reuse the docker-compose files and deploy apps both on Swarm and Kubernetes (think POC\u2019s or migrations user cases)<\/li>\n<li>You\u2019ll have one registry for local docker images and the Kubernetes cluster (not the case with minikube for example)<\/li>\n<\/ul>\n<p>There are also some disadvantages:<\/p>\n<ul>\n<li>The Kubernetes version is hardcoded<\/li>\n<li>It\u2019s more or less a \u201cread-only\u201d Kubernetes that you can\u2019t really change<\/li>\n<li>Mixing the terminologies (use docker cli to deploy to k8s) can become somehow confusing<\/li>\n<\/ul>\n<p>If you\u2019re completely new to Kubernetes but you\u2019re familiar with Docker, this approach allows you to get a pick at what K8s can do from a safe zone (docker cli). But for application debugging and writing manifests, you\u2019ll need to learn some Kubernetes.<\/p>\n<p>In the docker style, the implementation is clean, simple and user-friendly. Will this make minikube obsolete? For casual users probably yes. But, if you want to run a specific version of Kubernetes, specific add-ons or for more advanced use cases, minikube is still the way to go. Further integration will come into the Docker stack, so for enterprise and Windows, keep an eye <a href=\"https:\/\/beta.docker.com\">here<\/a>.<\/p>\n<p><a href=\"https:\/\/container-solutions.com\/docker-for-mac-with-kubernetes-support\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jan 29, 2018 by Catalin Jora During DockerCon Copenhagen, Docker announced support and integration for Kubernetes, alongside Swarm. The first integration is in the Docker for Mac, where you can run now a 1 node Kubernetes cluster. This allows you to deploy apps with Docker-compose files to that local Kubernetes cluster via the docker cli. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw93\/index.php\/2018\/10\/16\/docker-for-mac-with-kubernetes-support\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Docker for Mac with Kubernetes support&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/comments?post=352"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":494,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/352\/revisions\/494"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/media?parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/categories?post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/tags?post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}