Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Herding your containers and services

Herding your containers and services

Herding your sites and services

Whether you are moving away from a monolithic web application to a microservices oriented architecture or just have loads of sites to manage; you can benefit from running your own private managed cloud. In this talk, I will be introducing you to the wondrous world of containers and container orchestration using Docker, Rancher and Cattle. Even if you don’t plan on a really large infrastructure, as soon as you have more than a couple of servers you too can benefit from this.

Hoe sites en diensten te hoeden

Of je aan het overstappen bent van een monolitisch web applicatie naar een architectuur met microservices of je hebt heel veel sites te beheren; je kan door het inzetten van je eigen privé cloud een hoop besparen. In deze presentatie geef ik een introductie in de wonderlijke wereld van containers en container orchestration middels Docker, Rancher en Cattle. Zelfs als je niet van plan bent om een grote infrastructuur te beheren, zodra je al meer dan een paar servers beheert kan je voordeel hebben van deze techniek.

Mike van Riel

April 18, 2017
Tweet

More Decks by Mike van Riel

Other Decks in Technology

Transcript

  1. MIKE VAN RIEL ➤ Part of Ingewikkeld ➤ Architect, Engineer,

    Trainer, Coach and Game Developer ➤ Lead Developer for phpDocumentor ➤ Game Designer for Elrakis ➤ Contributor for many projects
  2. SERVER2 SERVER1 AND BILLY MOVES OUT OF THE HOUSE PHP

    MYSQL BILLY PHP PHP OHHH. A MIGRATION!
  3. SERVER2 SERVER1 BUT BILLY STILL WANTS A FRIEND TO KEEP

    HIS STUFF PHP MYSQL BILLY PHP PHP MORE MAINTENANCE
  4. SERVER2 SERVER1 BILLY NEEDS TO CLONE HIMSELF PHP MYSQL BILLY

    PHP PHP SERVER3 BILLY MORE MAINTENANCE
  5. SERVER2 SERVER1 PSST. YOU KNOW YOU PAY TOO MUCH? PHP

    MYSQL BILLY PHP PHP SERVER3 BILLY WASTE
  6. SERVER2 SERVER1 AND BILLY GROWS EVEN MORE PHP MYSQL BILLY

    PHP PHP SERVER3 BILLY REDIS ELASTIC
  7. A SHORT SUMMARY ➤ When a web app grows it

    gets more dependencies ➤ Apps become woven with the server ➤ As a result migration is painful ➤ Servers pollute during their lifecycle ➤ Server configuration goes out of sync after time ➤ As a result maintenance costs rise
  8. CONTAINERS ARE SELF-CONTAINED SERVICES ➤The more isolated a container, the

    better it works: ➤Should be stateless ➤Should be independent ➤Should be disposable ➤Should not need scripted provisioning
  9. “ Containers, by their nature, do not know or care

    whether you run them locally or on production
  10. PULLING A RABBIT OUT OF A CONTAINER docker run -d

    -p15672:15672 rabbitmq:management
  11. DID IT WORK AND WHAT IS THE STATUS? CONTAINER ID

    IMAGE COMMAND CREATED STATUS PORTS NAMES 43685e9df887 killing-billy "docker-php-entryp..." 4 seconds ago Up 2 seconds 0.0.0.0:8042->80/tcp heuristic_mcclintock $ docker ps
  12. WHAT ABOUT PROVISIONING? ➤ Some applications require provisioning ➤ Often

    provisioning is more like priming ➤ Do this while building your container using the RUN command ➤ Or do this as part of starting the container using the CMD or ENTRYPOINT command
  13. DOCKER-COMPOSE.YML database: image: mysql:latest ports: [ “3306:3306" ] environment: MYSQL_ROOT_PASSWORD:

    "secret" website: env_file: .env build: . ports: [ "8042:80" ] volumes: - .:/var/www/html links: - database
  14. REGISTRIES ➤ Containers can be stored in ‘registries’ ➤ Public

    registries such as http://hub.docker.com ➤ Private registries ➤ Self-hosted ➤ Gitlab.com ➤ Quay.io ➤ Docker Hub ➤ And more…
  15. BUILDING A CONTAINER - .GITLAB-CI.YML build: stage: build image: "docker:git"

    services: [ "docker:dind" ] cache: { paths: [ vendor/ ] } # install dependencies before_script: - docker run -t -v $CI_PROJECT_DIR:/app --env-file $CI_PROJECT_DIR/.env composer/composer install -o --no-interaction --no-dev --ignore-platform-reqs -- no-progress script: # build container - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com - docker build -t registry.gitlab.com/ingewikkeld/
  16. A SHORT SUMMARY ➤ Containers are isolated from the server

    ➤ They are cheap to create and destroy ➤ They can be combined together to form a more intricate system ➤ Building and provisioning is easy and automated ➤ You can run them anywhere (provided Docker is installed)
  17. A SERVER-AGNOSTIC LAYER Without orchestration, containers are bound to a

    specific server With orchestration, containers are free to move around
  18. “ This is why containers must be disposable; they should

    be able to be destroyed and created arbitrarily
  19. “ This is why containers must not be post-provisioned; they

    should be able to be destroyed and created quickly
  20. REMEMBER THE DOCKER-COMPOSE.YML? database: image: mysql:latest ports: [ “3306:3306" ]

    environment: MYSQL_ROOT_PASSWORD: "secret" website: env_file: .env build: . ports: [ "8042:80" ] volumes: - .:/var/www links: - database
  21. ENVIRONMENTS, STACKS AND SERVICES Environment Stack Service Service Stack Service

    Environment Stack Service Service Stack Service Environment Stack Service Service Stack Service
  22. ENVIRONMENTS, STACKS AND SERVICES Test Billy MySQL PHP Stack PHP

    Acceptance Billy MySQL PHP Stack PHP Production Billy MySQL PHP Stack PHP
  23. STARTING A RANCHER SERVER database: image: mariadb:latest env_file: .env volumes:

    - "/mnt/mariadb:/var/lib/mysql" restart: unless-stopped rancher: image: rancher/server env_file: .env container_name: rancher-server ports: - "8080:8080" restart: unless-stopped links: - "database" docker-compose.yml
  24. RANCHER SERVER - ENVIRONMENT VARIABLES MYSQL_ROOT_PASSWORD=[INSERT PASSWORD] MYSQL_DATABASE=cattle MYSQL_USER=cattle MYSQL_PASSWORD=[INSERT

    THE CATTLE USER PASSWORD] CATTLE_DB_CATTLE_DATABASE=mysql CATTLE_DB_CATTLE_MYSQL_HOST=database CATTLE_DB_CATTLE_MYSQL_NAME=cattle CATTLE_DB_CATTLE_USERNAME=cattle CATTLE_DB_CATTLE_PASSWORD=[INSERT THE CATTLE USER PASSWORD] .env
  25. BUILDING A CONTAINER - .GITLAB-CI.YML build: stage: build image: "docker:git"

    services: [ "docker:dind" ] cache: { paths: [ vendor/ ] } # install dependencies before_script: - docker run -t -v $CI_PROJECT_DIR:/app --env-file $CI_PROJECT_DIR/.env -e SYMFONY_ENV=prod composer/composer install -o --no-interaction --no-dev --ignore-platform-reqs -- no-progress script: # build container - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com - docker build -t registry.gitlab.com/ingewikkeld/
  26. DEPLOYING A CONTAINER - .GITLAB-CI.YML stages: - build - deploy

    build [...] deploy: stage: deploy image: cdrx/rancher-gitlab-deploy variables: { GIT_STRATEGY: none } script: # deploy container to registry - upgrade --environment="ingewikkeld" --stack="wecamp" --service="website" --finish-upgrade only: - master
  27. THINGS TO WATCH OUT FOR Because containers move around PORT

    CONFLICTS Use load balancers to direct traffic to the right service. DNS Use services that dynamically update your DNS records. PERSISTENT STORAGE Use cloud-based file storage, NFS or build your app for this using FlySystem.
  28. THANK YOU ➤ Contact me on twitter: @mvriel ➤ Please

    leave a rating on joind.in ➤ If you have questions that don’t fit in 140 characters: [email protected] BILLY