Infrastructure Deployment with Docker & Ansible - Comment
This is an introduction to Docker & Ansible. It shows how Ansible can be used as orchestration too for Docker. There are 2 real world examples included with code examples in a Gist. Topics covered: 1. Infrastructure Deployment with 2. Who I am? • Robert Reiz • Software Developer • I started VersionEye • Software Dev since 1998 3. Agenda ❖ Intro to Docker ❖ Demo ❖ Intro to Ansible ❖ Demo 4. Shipment without Containers 5. 1956 Malcom McLean introduced the 40’Container - ISO 668. > 15 Million inst. 2/3 of global trade run over 40’Containers! 6. The Logistic Problem 7. Same Problem in Software Dev. 8. Java ? ? ? Ruby ? ? ? Node.JS ? ? ? MySQL ? ? ? Dev-Env. Test-Env. Prod-Env. 9. Java JKD 1.8.14 - Win32 JKD 1.8.1 - Lnx-64 JDK 1.7-patch UNX Ruby 2.2.2 rvm 2.2.1 nat MRI 2.1.0 rubinius Node.JS 4.0 win 4.0 Linux 4.0 Linux MySQL 5.5 win 5.0 Linux 5.0 Linux Dev-Env. Test-Env. Prod-Env. 10. Java Ruby Node.JS MySQL Dev-Env. Test-Env. Prod-Env. 11. What is Docker? 12. What is Docker? ❖ Open Source Project started in March 2013 ❖ From the makers of dotCloud (PaaS). ❖ Received $162 Million Funding. ❖ Community grows rapidly! 13. What is Docker? ❖ Tiny VM (25 MB) ❖ Linux based - LXC Interface / libcontainer ❖ Own Namespaces and Cgroups! ❖ Shared resources with host system. ❖ Changes changed in Layers. Similar to Git! ❖ Originally not for Windows & Mac ! But … ->https://docs.docker.com/installation/windows/ -> https://blog.docker.com/2016/03/docker-for-mac-windows-beta/ 14. Build - Ship - Run Docker-Hub Build RUN RUN RUN docker push docker pull Server Farm Production 15. Build 16. Dockerfile FROM ubuntu:14.10 MAINTAINER Robert Reiz ENV LANG en_US.UTF-8 RUN apt-get update RUN apt-get install -y --force-yes -q nginx ADD nginx.conf /etc/nginx/nginx.conf CMD nginx EXPOSE 80 17. Build - Dockerfile > docker build -t reiz/nginx:1.0.0 . docker image => reiz/nginx:1.0.0 18. Ship 19. Ship Docker Image > docker push reiz/nginx:1.0.0 20. Run 21. Fetch a Docker Image > docker pull reiz/nginx:1.0.0 Download docker image reiz/nginx:1.0.0 from Docker Hub to local Docker repository. 22. Run a Docker Container > docker run reiz/nginx:1.0.0 Creates a Docker container out of the Docker image reiz/nginx:1.0.0. It runs the nginx process. 23. More Commands > docker stop > docker start > docker top > docker logs > docker rm 24. Important ❖ A Docker Container doesn’t store state! ❖ You can not ssh into a Docker Container! ❖ A container is supposed to run 1 process! 25. Shell 26. Get a Shell > docker run -it reiz/mongodb:3.2.0 /bin/bash Starts a new Docker container with an active shell. 27. Volumes 28. Mount a Volume > docker run -v/mnt/mongodb:/data -d reiz/mongodb:3.2.0 Mounts “/mnt/mongodb” directory into the Docker container as “/data”. Keep the data on the host. That’s how you keep data persisted. 29. Environment Variables 30. Set environment variables > docker run --envLANG=en_US.UTF-8 -d reiz/mongodb:3.2.0 You can overwrite ENV variables from the Dockerfile here and also define completely new ones. 31. Links 32. Link Docker Containers > docker run —name mongodb -d versioneye/mongodb:1.0.2 > docker run —linkmongodb:mongo versioneye/api:1.0.0 MONGO_PORT=tcp://172.1.10.1:27017 MONGO_PORT_27017_TCP=tcp://172.1.10.1:27017 MONGO_PORT_27017_TCP_ADDR=172.1.10.1 MONGO_PORT_27017_TCP_PORT=27017 MONGO_PORT_27017_TCP_PROTO=tcp Environmentvariablesareinjectedin2ndcontainer: 33. Link Docker Containers Linking only works on same hosts! 34. Docker Compose api: image: versioneye/rails_api:2.5.7 ports: - "9090:9090" container_name: "api" links: - mongodb:db - elasticsearch:es mongodb: image: reiz/mongodb:2.6.6_2 container_name: “mongodb" elasticsearch: image: reiz/elasticsearch:0.9.1 container_name: "elasticsearch" docker-compose.yml describes a whole set of Docker containers 35. Docker Compose > docker-compose up -d > docker-compose ps > docker-compose stop 36. Docker Compose > docker-compose build api > docker-compose up --no-deps -d api Updating a single container, not ALL of them. 37. Docker Compose > docker-compose scale worker=3 Scaling up containers 38. DEMO 39. Service Discovery 40. Service Discovery ❖ Environment Variables ❖ Mount configuration via volumes ❖ Linking ❖ Use a service like: etcd, zookeeper etc… 41. Orchestration 42. Docker Orchestration ❖ CM-Tools (Chef, Puppet, Ansible, Salt) ❖ http://kubernetes.io/ ❖ https://coreos.com/ ❖ https://docs.docker.com/swarm/ ❖ https://www.openshift.com/ 43. 2012 VersionEye is running on Heroku. 44. 2013 VersionEye moves to AWS because of the Amazon Activate Program! 45. WWW API APP x 3 RabbitMQ Tasks MongoDB MongoDB MongoDB Elastic Search Memcached Crawlers x N VersionEye Infrastructure 46. Handcrafted Servers are ❖ hardtomaintain ❖ verytime/costintensive ❖ setupisnoteasilyreproducible ❖ manytimesverybuggy 47. Reasons for Ansible ❖ No Master ❖ No Agents ❖ Configuration in Yaml ❖ Very easy to learn 48. Server Server Server Server You SSH Ansible works via SSH. No Master Server! No Agent on the Server is required. 49. Installation 50. sudo pip install ansible 51. brew update brew install ansible 52. Ansible Concepts ❖ Inventory ❖ Playbooks ❖ Roles ❖ Tasks / Handlers / Vars ❖ Modules 53. Inventory 54. Inventory [mongo_master] 168.197.1.14 [mongo_slaves] 168.197.1.15 168.197.1.16 168.197.1.17 [www] 168.197.1.2 Inventory files are simple text files which describe your servers. IP Addresses or DNS Names grouped by names. 55. Inventory [mongo_master] 168.197.1.14 [mongo_slaves] mongo1.server mongo2.server mongo3.server [www] 168.197.1.2 List of target hosts. Usually located in /etc/ansible/hosts 56. Inventory [mongo_master] mongo-[a:c]-server [mongo_slaves] mongo[1:3].server [www] {{my_little_webserver}} Inventory files can take advantage of variables and enumerations 57. Playbooks 58. Simple Playbook --- - hosts: dev_servers user: ubuntu sudo: true roles: - java - memcached - hosts: www_servers user: ubuntu sudo: true roles: - java group name from the inventory file server auth Role which should be installed on the server 59. Roles / Modules 60. simpple role with apt module --- - name: update debian packages apt: update_cache=true - name: install Java JDK apt: name=openjdk-7-jdk state=present 61. apt module --- - name: update debian packages apt: update_cache=true - name: install Java JDK apt: name=openjdk-7-jdk state=present Documentation of this step! Module Parameters of the Module 62. --- - name: update debian packages apt: update_cache=true - name: upgrade packages apt: upgrade=full - name: ensure that basic packages are installed apt: name={{ item }} state=present with_items: - tree - wget - links2 - gcc - g++ - make - autoconf - automake - libssl-dev - libcurl4-openssl-dev 63. Thousands of Modules 64. shell module --- - name: do what you want shell: /opt/I_can_do_what_I_want.sh 65. A role directory 66. Variables --- app_dir: /var/www/versioneye tomcat/vars/main.yml --- - name: create versioneye directory command: mkdir -p {{ app_dir }} tomcat/tasks/main.yml 67. Handlers --- - name: restart mongodb service: name=mongod state=restarted mongo/handlers/main.yml - name: copy MongoDB configuration to the server copy: src=mongodb.conf dest=/etc/mongodb.conf notify: restart mongodb mongo/tasks/main.yml 68. Files mongo/files/mongodb.list - name: add MongoDB debian server to the list of servers copy: src=mongodb.list dest=/etc/apt/sources.list.d/mongodb.list mongo/tasks/main.yml 69. Real World Use case 70. Loadbalancer APP APP APP Seamless Web App Deployment @ VersionEye https://gist.github.com/reiz/238e70683bbfbc10bf4c 71. Loadbalancer APP APP APP Docker Hub 1. Build new Docker Image 2. push 3. run Seamless Web App Deployment @ VersionEye https://gist.github.com/reiz/238e70683bbfbc10bf4c 72. Loadbalancer APP APP APP Docker Hub 1. pull 2. run Seamless Web App Deployment @ VersionEye https://gist.github.com/reiz/238e70683bbfbc10bf4c 73. Loadbalancer APP APP APP Seamless Web App Deployment @ VersionEye Docker Hub 1. pull 2. run https://gist.github.com/reiz/238e70683bbfbc10bf4c 74. Loadbalancer APP APP APP Seamless Web App Deployment @ VersionEye https://gist.github.com/reiz/238e70683bbfbc10bf4c 75. Demo 76. ? ? ? @RobertReiz |
|||
Posted by : peter88 | Post date : 2020-01-06 16:23 | ||
Category : Technology | Views : 467 | ||
New Comment