1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<h1>Orchestration</h1>
<p>The portability and reproducibility of a containerized process provides an opportunity to move and scale our containerized applications across clouds and datacenters. Containers effectively guarantee that those applications run the same way anywhere, allowing us to quickly and easily take advantage of all these environments. Additionally, as we scale our applications up, we need some tooling to help automate the maintenance of those applications, enable the replacement of failed containers automatically, and manage the rollout of updates and reconfigurations of those containers during their lifecycle.</p> <p>Tools to manage, scale, and maintain containerized applications are called <em>orchestrators</em>, and the most common examples of these are <em>Kubernetes</em> and <em>Docker Swarm</em>. Development environment deployments of both of these orchestrators are provided by Docker Desktop, which we’ll use throughout this guide to create our first orchestrated, containerized application.</p> <p>The advanced modules teach you how to:</p> <ol> <li><a href="../kube-deploy/index">Set up and use a Kubernetes environment on your development machine</a></li> <li><a href="../swarm-deploy/index">Set up and use a Swarm environment on your development machine</a></li> </ol> <h2 id="enable-kubernetes">Enable Kubernetes</h2> <p>Docker Desktop will set up Kubernetes for you quickly and easily. Follow the setup and validation instructions appropriate for your operating system:</p> <ul class="nav nav-tabs"> <li class="active"><a data-toggle="tab" href="#kubeosx">Mac</a></li> <li><a data-toggle="tab" href="#kubewin">Windows</a></li> </ul> <div class="tab-content"> <div id="kubeosx" class="tab-pane fade in active"> <h3 id="mac">Mac</h3> <ol> <li> <p>After installing Docker Desktop, you should see a Docker icon in your menu bar. Click on it, and navigate to <strong>Preferences</strong> > <strong>Kubernetes</strong>.</p> </li> <li> <p>Check the checkbox labeled <strong>Enable Kubernetes</strong>, and click <strong>Apply & Restart</strong>. Docker Desktop will automatically set up Kubernetes for you. You’ll know that Kubernetes has been successfully enabled when you see a green light beside ‘Kubernetes <em>running</em>’ in the Preferences menu.</p> </li> <li> <p>In order to confirm that Kubernetes is up and running, create a text file called <code class="language-plaintext highlighter-rouge">pod.yaml</code> with the following content:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: testpod
image: alpine:latest
command: ["ping", "8.8.8.8"]
</pre></div> </div> <p>This describes a pod with a single container, isolating a simple ping to 8.8.8.8.</p> </li> <li> <p>In a terminal, navigate to where you created <code class="language-plaintext highlighter-rouge">pod.yaml</code> and create your pod:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ kubectl apply -f pod.yaml
</pre></div> </div> </li> <li> <p>Check that your pod is up and running:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ kubectl get pods
</pre></div> </div> <p>You should see something like:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">NAME READY STATUS RESTARTS AGE
demo 1/1 Running 0 4s
</pre></div> </div> </li> <li> <p>Check that you get the logs you’d expect for a ping process:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ kubectl logs demo
</pre></div> </div> <p>You should see the output of a healthy ping process:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=37 time=21.393 ms
64 bytes from 8.8.8.8: seq=1 ttl=37 time=15.320 ms
64 bytes from 8.8.8.8: seq=2 ttl=37 time=11.111 ms
...
</pre></div> </div> </li> <li> <p>Finally, tear down your test pod:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ kubectl delete -f pod.yaml
</pre></div> </div> </li> </ol> </div> <div id="kubewin" class="tab-pane fade"> <h3 id="windows">Windows</h3> <ol> <li> <p>After installing Docker Desktop, you should see a Docker icon in your system tray. Right-click on it, and navigate <strong>Settings</strong> > <strong>Kubernetes</strong>.</p> </li> <li> <p>Check the checkbox labeled <strong>Enable Kubernetes</strong>, and click <strong>Apply & Restart</strong>. Docker Desktop will automatically set up Kubernetes for you. You’ll know that Kubernetes has been successfully enabled when you see a green light beside ‘Kubernetes <em>running</em>’ in the <strong>Settings</strong> menu.</p> </li> <li> <p>In order to confirm that Kubernetes is up and running, create a text file called <code class="language-plaintext highlighter-rouge">pod.yaml</code> with the following content:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: testpod
image: alpine:latest
command: ["ping", "8.8.8.8"]
</pre></div> </div> <p>This describes a pod with a single container, isolating a simple ping to 8.8.8.8.</p> </li> <li> <p>In PowerShell, navigate to where you created <code class="language-plaintext highlighter-rouge">pod.yaml</code> and create your pod:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ kubectl apply -f pod.yaml
</pre></div> </div> </li> <li> <p>Check that your pod is up and running:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ kubectl get pods
</pre></div> </div> <p>You should see something like:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">NAME READY STATUS RESTARTS AGE
demo 1/1 Running 0 4s
</pre></div> </div> </li> <li> <p>Check that you get the logs you’d expect for a ping process:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ kubectl logs demo
</pre></div> </div> <p>You should see the output of a healthy ping process:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=37 time=21.393 ms
64 bytes from 8.8.8.8: seq=1 ttl=37 time=15.320 ms
64 bytes from 8.8.8.8: seq=2 ttl=37 time=11.111 ms
...
</pre></div> </div> </li> <li> <p>Finally, tear down your test pod:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ kubectl delete -f pod.yaml
</pre></div> </div> </li> </ol> </div> </div> <h2 id="enable-docker-swarm">Enable Docker Swarm</h2> <p>Docker Desktop runs primarily on Docker Engine, which has everything you need to run a Swarm built in. Follow the setup and validation instructions appropriate for your operating system:</p> <ul class="nav nav-tabs"> <li class="active"><a data-toggle="tab" href="#swarmosx">Mac</a></li> <li><a data-toggle="tab" href="#swarmwin">Windows</a></li> </ul> <div class="tab-content"> <div id="swarmosx" class="tab-pane fade in active"> <h3 id="mac">Mac</h3> <ol> <li> <p>Open a terminal, and initialize Docker Swarm mode:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker swarm init
</pre></div> </div> <p>If all goes well, you should see a message similar to the following:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">Swarm initialized: current node (tjjggogqpnpj2phbfbz8jd5oq) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3e0hh0jd5t4yjg209f4g5qpowbsczfahv2dea9a1ay2l8787cf-2h4ly330d0j917ocvzw30j5x9 192.168.65.3:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
</pre></div> </div> </li> <li> <p>Run a simple Docker service that uses an alpine-based filesystem, and isolates a ping to 8.8.8.8:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker service create --name demo alpine:latest ping 8.8.8.8
</pre></div> </div> </li> <li> <p>Check that your service created one running container:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker service ps demo
</pre></div> </div> <p>You should see something like:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
463j2s3y4b5o demo.1 alpine:latest docker-desktop Running Running 8 seconds ago
</pre></div> </div> </li> <li> <p>Check that you get the logs you’d expect for a ping process:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker service logs demo
</pre></div> </div> <p>You should see the output of a healthy ping process:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">demo.1.463j2s3y4b5o@docker-desktop | PING 8.8.8.8 (8.8.8.8): 56 data bytes
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=0 ttl=37 time=13.005 ms
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=1 ttl=37 time=13.847 ms
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=2 ttl=37 time=41.296 ms
...
</pre></div> </div> </li> <li> <p>Finally, tear down your test service:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker service rm demo
</pre></div> </div> </li> </ol> </div> <div id="swarmwin" class="tab-pane fade"> <h3 id="windows">Windows</h3> <ol> <li> <p>Open a powershell, and initialize Docker Swarm mode:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker swarm init
</pre></div> </div> <p>If all goes well, you should see a message similar to the following:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">Swarm initialized: current node (tjjggogqpnpj2phbfbz8jd5oq) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3e0hh0jd5t4yjg209f4g5qpowbsczfahv2dea9a1ay2l8787cf-2h4ly330d0j917ocvzw30j5x9 192.168.65.3:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
</pre></div> </div> </li> <li> <p>Run a simple Docker service that uses an alpine-based filesystem, and isolates a ping to 8.8.8.8:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker service create --name demo alpine:latest ping 8.8.8.8
</pre></div> </div> </li> <li> <p>Check that your service created one running container:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker service ps demo
</pre></div> </div> <p>You should see something like:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
463j2s3y4b5o demo.1 alpine:latest docker-desktop Running Running 8 seconds ago
</pre></div> </div> </li> <li> <p>Check that you get the logs you’d expect for a ping process:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker service logs demo
</pre></div> </div> <p>You should see the output of a healthy ping process:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">demo.1.463j2s3y4b5o@docker-desktop | PING 8.8.8.8 (8.8.8.8): 56 data bytes
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=0 ttl=37 time=13.005 ms
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=1 ttl=37 time=13.847 ms
demo.1.463j2s3y4b5o@docker-desktop | 64 bytes from 8.8.8.8: seq=2 ttl=37 time=41.296 ms
...
</pre></div> </div> </li> <li> <p>Finally, tear down your test service:</p> <div class="highlight"> <div class="highlight"><pre class="highlight" data-language="">$ docker service rm demo
</pre></div> </div> </li> </ol> </div> </div> <h2 id="conclusion">Conclusion</h2> <p>At this point, you’ve confirmed that you can run simple containerized workloads in Kubernetes and Swarm. The next step will be to write the Kubernetes yaml that describes how to run and manage these containers on Kubernetes.</p> <p><a href="../kube-deploy/index" class="button primary-btn" style="margin-bottom: 30px; margin-right: 200%">On to deploying to Kubernetes >></a></p> <p>To learn how to write the stack file to help you run and manage containers on Swarm, see <a href="../swarm-deploy/index">Deploying to Swarm</a>.</p> <h2 id="cli-references">CLI references</h2> <p>Further documentation for all CLI commands used in this article are available here:</p> <ul> <li><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply"><code class="language-plaintext highlighter-rouge">kubectl apply</code></a></li> <li><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get"><code class="language-plaintext highlighter-rouge">kubectl get</code></a></li> <li><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs"><code class="language-plaintext highlighter-rouge">kubectl logs</code></a></li> <li><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#delete"><code class="language-plaintext highlighter-rouge">kubectl delete</code></a></li> <li><a href="../../engine/reference/commandline/swarm_init/index"><code class="language-plaintext highlighter-rouge">docker swarm init</code></a></li> <li><a href="../../engine/reference/commandline/service/index"><code class="language-plaintext highlighter-rouge">docker service *</code></a></li> </ul>
<p><a href="https://docs.docker.com/search/?q=orchestration">orchestration</a>, <a href="https://docs.docker.com/search/?q=deploy">deploy</a>, <a href="https://docs.docker.com/search/?q=kubernetes">kubernetes</a>, <a href="https://docs.docker.com/search/?q=swarm">swarm</a></p>
<div class="_attribution">
<p class="_attribution-p">
© 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br>
<a href="https://docs.docker.com/get-started/orchestration/" class="_attribution-link">https://docs.docker.com/get-started/orchestration/</a>
</p>
</div>
|