Downloading and installing Docker for Mac. For now, Kubernetes is only available on Docker for Mac 17.12 CE Edge (special Docker version for new and experimental features), so make sure you install the Edge version. On your Mac, double-click the Docker.dmg file and begin the installation process as instructed. Kubernetesを内蔵したDocker for Macがリリースされたらしいので、試してみた kubectlコマンドでkubernetes-dashboardのデプロイ、docker stackコマンドでmetabaseをデプロイしてみた.
6 January 2018 Kubernetes-powered Docker CE (Community Edition) When that they will be supporting natively, I was pretty curious how that would work. Obviously, after the announcement, I checked if the Edge version already supports it since. Unfortunately, during that time, it was not! After waiting for a few months, it has finally arrived! Just saw the update this morning, looks like is now experimental in Docker CE(Community Edition). Based on the releae notes, it is now available in version 17.12.0-ce.
I am running Edge so I'm not sure if this is available in the mainstream version as well. Will update this blog once I've tried. Of course, once I saw this notification, I immediately installed the update. After installation, you still need to enable Kubernetes in Preferences.
After enabling Kubernetes, I tried to execute kubectl commands and it can't connect to the kubernetes server. So that didn't work straight out of the box! But, it's really my Mac's configuration. I saw in that if you've used minikube before, you need to switch the context.
Just execute this command. Kubectl config use-context docker-for-desktop Now, it works! We don't see any timeout error anymore! Let's get to the fun part. As promised, docker commands should work with Kubernetes in Docker. So let's create a new deployment using a docker stack compose file.
I used this sample compose file from my repo. Demo-docker-kube-stack.yml version: '3.3' services: ms1: image: melvindave/spring-boot-example ports: - '8080:8080' networks: - backend deploy: replicas: 3 nginx: image: nginx ports: - '80:80' networks: - frontend deploy: replicas: 1 networks: backend: You can download the compose file from my repo Deploy the Stack in our Kubernetes cluster $ docker stack deploy -namespace docker-kube-demo -compose-file demo-docker-kube-stack.yml demo-docker-kube-stack Wait a few seconds, and you'll see that the services have started. Services in Kubernetes are similar to Services in Swarm. Pods are containers. You can also get more info for each service by using this command. $ kubectl describe service To check containers, you can also do a 'docker ps'.
![Docker For Mac Kubernetes Dashboard Docker For Mac Kubernetes Dashboard](/uploads/1/2/5/4/125423624/574672822.png)
Should be equivalent to 'kubectl get pods'. To be able to access the service from the host which in this case is my Mac, you need to expose the service using the NodePort type. $ kubectl expose deployment ms1 -type=NodePort -name=ms1-service $ kubectl expose deployment nginx -type=NodePort -name=nginx-service After executing this, you can now access both services from the browser. Now we have a stack running in a Kubernetes cluster within Docker!
Running another Stack using Swarm simultaneously Once you've enabled Kubernetes in Docker CE, it will have Kubernetes as the default orchaestrator instead of Swarm. If you would like to use Swarm simultaneously with Kubernetes, you need to set the DOCKERORCHESTRATOR env variable to switch to Swarm. Let's deploy the same stack in Swarm. $ DOCKERORCHESTRATOR=swarm docker stack deploy -compose-file demo-docker-kube-stack.yml demo-docker-swarm-stack After a few seconds, services will start. Note that if you want to check services or stacks in Swarm, you always need to set the DOCKERORCHESTRATOR env variable before every command. If you don't pass this, it will assume, it orchestrator is kubernetes.
Notice the difference below. However, 'docker ps' will list all containers whether it is in Kubernetes or Swarm. Kubernetes Dashboard Since we already have Kubernetes running, let's install the Just execute 2 commands $ kubectl apply -f $ kubectl proxy Then access the dashboard using your browser Overview View Deployments, Pods, Replica Sets and Services View logs of a Pod That's it!
Hope you share your experience with Kubernetes in Docker! Feel free to add your comments below.
Let's connect in,! Read by this author.