📜 ⬆️ ⬇️

Using Docker CE (Community Edition) with Kubernetes

Note trans. : The author of the article, Melvin Dave Vivas, who heads the development team and SRE engineers at a Singapore-based bank, shares his experience of getting acquainted with Kubernetes support in the Docker platform.

When in October last year at DockerCon 2017, Docker Inc CTO Solomon Hykes (Solomon Hykes) announced the native support of Kubernetes, I was very curious how this would work.


')
Therefore, after the announcement, I decided to check for this support in the Edge version, as Michael Frills wrote in the Docker blog. But at that time it was not there. And now, after several months of waiting, it finally appeared.

Kubernetes experimental support in Docker CE (Community Edition) was introduced in the January update. In the Release Notes it is reported that it appeared from version 17.12.0-ce. I myself use Edge, so I'm not sure that the update is available in the mainstream version.



In general, seeing such a notification, I installed the update. After the installation, however, you still need to enable Kubernetes in the Preferences settings:



After activating Kubernetes, I tried to execute commands with kubectl , but the connection to the server returned an error:



Out of the box did not work, but the whole thing turned out to be in my specific configuration. As reported in the Docker documentation , if you used Minikube before, you need to switch context. To do this, run the command:

 $ kubectl config use-context docker-for-desktop 



After that, everything works - errors about the timeout are gone:



Time to go to the interesting part. As promised, docker teams should work with Kubernetes in the Docker. Create a new deployment based on the Compose file for the docker stack. I used demo-docker-kube-stack.yml , which can be taken from this repository :

 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: 

The stack stack in the 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 will see that the services have started. Services in Kubernetes are similar to Services in Swarm, and served as containers.



More information about each service can be obtained using this command:

 $ kubectl describe services <service-name> 



You can check containers with docker ps . The output should be equivalent to kubectl get pods :



To be able to access the service from the host, which in my case was a Mac computer, you need to open 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 these commands, both services are accessible from the browser:



Fine! Our Stack is running on the Kubernetes cluster.

Simultaneously launching another Stack in Swarm


By enabling Kubernetes in Docker CE, this system will become the default orchestrator instead of Swarm. If you want to use Swarm simultaneously with Kubernetes, you need to set the environment variable DOCKER_ORCHESTRATOR to swarm .

Close the same stack in swarm:

 $ DOCKER_ORCHESTRATOR=swarm docker stack deploy --compose-file demo-docker-kube-stack.yml demo-docker-swarm-stack 



After a few seconds, the services will start:



Note that if you want to check Services / Stacks in Swarm, always (before each command) you need to determine the value of the environment variable DOCKER_ORCHESTRATOR . If you do not change it, Kubernetes will play the role of the orchestrator:



At the same time, docker ps will list all containers, be they in Kubernetes or in Swarm:



Kubernetes Dashboard


Once Kubernetes works with us, let's install its dashboard. To do this, just run two commands:

 $ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml $ kubectl proxy 



After that, it will be available in the browser at http: // localhost: 8001 / api / v1 / namespaces / kube-system / services / https: kubernetes-dashboard: / proxy / #! / Overview? Namespace = default .

General form:



View View Deployments, Pods, ReplicaSets, Services:



View logs



PS from translator


Read also in our blog:

Source: https://habr.com/ru/post/346802/


All Articles