Advertisement
Javi

docker-swarm-workshop-mac.md

Jan 28th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. <style>
  2. body {
  3. font-size: 1.75em;
  4. color: #202020;
  5. }
  6.  
  7. h1 {
  8. font-size: 2.25em;
  9. font-weight : 400;
  10. border-bottom: 1px dotted silver;
  11. }
  12.  
  13. h2 {
  14. background-color : #f3f3f3;
  15. padding: 8px;
  16. margin-bottom: 0.75em;
  17. clear : both;
  18. }
  19.  
  20. .container {
  21. width : 90%;
  22. max-width: 1024px;
  23. }
  24.  
  25. blockquote {
  26. float: right;
  27. background-color : #ffc0e0;
  28. width: 300px;
  29. }
  30.  
  31. @media (max-width: 1024px) {
  32. blockquote {
  33. display: none;
  34. }
  35. }
  36.  
  37. </style>
  38.  
  39. Container Orchestration with Docker Swarm
  40. ==================================================
  41.  
  42. Capside
  43. --------------------------------------------------
  44.  
  45. ![Hiring](https://pbs.twimg.com/media/CWM8GyGVAAAH7Lx.png:large)
  46.  
  47.  
  48. Docker FTW
  49. --------------------------------------------------
  50.  
  51. ![IT Problems](https://s3-us-west-2.amazonaws.com/ciberado/docker_ftw.png)
  52.  
  53. Key concepts quick review
  54. --------------------------------------------------
  55.  
  56. + Images
  57. + Dockerfile
  58. + Docker Hub
  59. + Host
  60. + Container
  61. + Swarm
  62.  
  63.  
  64. The project
  65. --------------------------------------------------
  66.  
  67. ![Diagrama Simplificado](https://s3-us-west-2.amazonaws.com/ciberado/docker-swarm-workshop-arquitectura.png)
  68.  
  69.  
  70. Setting up the Swarm registry
  71. --------------------------------------------------
  72.  
  73. ```bash
  74. docker-machine create -d virtualbox --virtualbox-memory "512" keystore
  75. docker-machine env keystore --shell bash
  76. eval "$(docker-machine env keystore --shell bash)"
  77. docker run -d -p 8500:8500 -h consul progrium/consul -server -bootstrap
  78. docker-machine ip keystore
  79. export consul_ip=$(docker-machine ip keystore)
  80. echo Consul IP: $consul_ip
  81. ```
  82.  
  83. Creating the Swarm master node
  84. --------------------------------------------------
  85.  
  86. ```bash
  87. docker-machine create \
  88. -d virtualbox \
  89. --virtualbox-memory "512" \
  90. --swarm --swarm-master \
  91. --swarm-discovery="consul://$consul_ip:8500" \
  92. --engine-opt="cluster-store=consul://$consul_ip:8500" \
  93. --engine-opt="cluster-advertise=eth1:2376" \
  94. master-node
  95. ```
  96.  
  97. Starting the worker nodes: API
  98. ---------------------------------------------------
  99.  
  100. ```bash
  101. docker-machine create -d virtualbox \
  102. --virtualbox-memory "512" \
  103. --swarm \
  104. --swarm-discovery="consul://$consul_ip:8500" \
  105. --engine-opt="cluster-store=consul://$consul_ip:8500" \
  106. --engine-opt="cluster-advertise=eth1:2376" \
  107. --engine-label noderole=api \
  108. cluster-node-1
  109. ```
  110.  
  111. Starting the worker nodes: DATABASE
  112. ---------------------------------------------------
  113.  
  114. ```bash
  115. docker-machine create -d virtualbox \
  116. --virtualbox-memory "512" \
  117. --swarm \
  118. --swarm-discovery="consul://$consul_ip:8500" \
  119. --engine-opt="cluster-store=consul://$consul_ip:8500" \
  120. --engine-opt="cluster-advertise=eth1:2376" \
  121. --engine-label noderole=db \
  122. cluster-node-2
  123. ```
  124.  
  125. Checking the cluster nodes
  126. ---------------------------------------------------
  127.  
  128. ```bash
  129. docker-machine env --shell bash master-node
  130. eval "$(docker-machine env --shell bash master-node)"
  131. docker ps --format "{{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Command}}"
  132. docker run swarm list consul://$consul_ip:8500
  133. ```
  134.  
  135. Connecting to the Swarm
  136. ---------------------------------------------------
  137.  
  138. ```bash
  139. docker-machine env --shell bash --swarm master-node
  140. eval "$(docker-machine env --shell bash --swarm master-node)"
  141. docker ps --format "{{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Command}}"
  142. docker ps --all --format "{{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Command}}"
  143. docker info
  144. ```
  145.  
  146. Creating the network
  147. ---------------------------------------------------
  148.  
  149. ```bash
  150. docker network create --driver overlay demonetwork
  151. docker network ls
  152. ```
  153.  
  154. Manually launching the database
  155. ---------------------------------------------------
  156.  
  157. ```bash
  158. docker run --name mysql -it --rm \
  159. --env "constraint:noderole==db" \
  160. --net demonetwork \
  161. capside/footballmatchdb
  162. ```
  163.  
  164. Manually launching the API
  165. ---------------------------------------------------
  166.  
  167. ```bash
  168. docker run -it --rm --name footballmatch \
  169. --env "constraint:noderole==api" \
  170. --net demonetwork \
  171. capside/docker-workshop-footballapi
  172. ```
  173.  
  174. Manually launching the proxy
  175. ---------------------------------------------------
  176.  
  177. ```bash
  178. docker run -it --rm --name haproxy \
  179. --env "constraint:noderole==api" \
  180. --net demonetwork \
  181. --publish 80:80 \
  182. capside/footballmatchlb
  183. ```
  184.  
  185. Checking the deployment
  186. ---------------------------------------------------
  187.  
  188. ```bash
  189. docker-machine ip cluster-node-1
  190. export api_ip=$(docker-machine ip cluster-node-1)
  191. ```
  192.  
  193.  
  194. Creating the Azure certificate
  195. ---------------------------------------------------
  196.  
  197. ```bash
  198. openssl req -x509 -nodes -days 365 -newkey rsa:1024 \
  199. -keyout swarmcert.pem -out swarmcert.pem
  200. openssl x509 -inform pem -in swarmcert.pem \
  201. -outform der -out swarmcert.cer
  202. ssh-keygen -y -f swarmcert.pem > swarmcert.pub
  203. ```
  204.  
  205. + Upload the certificate
  206. + Find the subscription id
  207.  
  208.  
  209. Setting the suscription id
  210. ---------------------------------------------------
  211.  
  212. ```bash
  213. set subscription_id=4c242bba-bb40-4f3b-b412-012345678901
  214. ```
  215.  
  216. Creating the keystore
  217. ---------------------------------------------------
  218.  
  219. ```bash
  220. docker-machine create \
  221. -d azure --azure-subscription-id="%subscription_id%" \
  222. --azure-subscription-cert="swarmcert.pem" \
  223. capside-keystore
  224. eval "$(docker-machine env --shell bash capside-keystore)"
  225. docker run -d -p 8500:8500 -h consul progrium/consul -server -bootstrap
  226. export consul_ip=$(docker-machine ip capside-keystore)
  227. ```
  228.  
  229. ####Endpoints
  230.  
  231. + 8500 tcp on the consul machine
  232.  
  233.  
  234. Launching the cluster
  235. ---------------------------------------------------
  236.  
  237. ```bash
  238. docker-machine create \
  239. -d azure --azure-subscription-id="%subscription_id%" \
  240. --azure-subscription-cert="swarmcert.pem" \
  241. --swarm --swarm-master \
  242. --swarm-discovery="consul://$consul_ip:8500" \
  243. --engine-opt="cluster-store=consul://$consul_ip:8500" \
  244. --engine-opt="cluster-advertise=eth0:2376" \
  245. capside-master-node
  246. eval "$(docker-machine env --shell bash capside-master-node)"
  247.  
  248. docker-machine create \
  249. -d azure --azure-subscription-id="%subscription_id%" \
  250. --azure-subscription-cert="swarmcert.pem" \
  251. --swarm \
  252. --swarm-discovery="consul://$consul_ip:8500" \
  253. --engine-opt="cluster-store=consul://$consul_ip:8500" \
  254. --engine-opt="cluster-advertise=eth0:2376" \
  255. --engine-label noderole=edge \
  256. capside-cluster-node-0
  257. ```
  258.  
  259. ####Endpoints
  260.  
  261. + 4789(udp), 7946(udp), 7946(tcp) on each swarm node including master
  262. + 80(tcp) on edge
  263.  
  264. Creating the network
  265. ---------------------------------------------------
  266.  
  267. ```bash
  268. docker network create --driver overlay demonetwork
  269. ```
  270.  
  271. Deploy on Azure: ARM
  272. ---------------------------------------------------
  273.  
  274. + Use the [ARM Template](https://github.com/Azure/azure-quickstart-templates/tree/master/docker-swarm-cluster)
  275.  
  276. Extra ball: dev environment
  277. ---------------------------------------------------
  278.  
  279. ```bash
  280. start docker run ^
  281. --net demonetwork -p 8888:8888 ^
  282. -v /c/Users/yourusername/api:/api ^
  283. --rm -it -e "TERM=xterm-256color" capside/nodejs sh
  284. ```
  285.  
  286. The first one is for free
  287. ---------------------------------------------------
  288.  
  289. ![Diagrama](https://s3-us-west-2.amazonaws.com/ciberado/docker-swarm-demo-haproxy.png)
  290.  
  291. [Online training](https://capside-academy.teachable.com/)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement