45
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible Oleksii Petrov Skelia Ukraine / ETwater Systems skype: alexhelkar twitter: @alexhelkar email: [email protected]

Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

  • Upload
    fwdays

  • View
    2.062

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible

Oleksii Petrov Skelia Ukraine / ETwater Systems skype: alexhelkar twitter: @alexhelkar email: [email protected]

Page 2: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

1. What for the goat needs an accordion?

Agenda

Page 3: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Agenda (real)1. SOA and Microservices 2. Dockerized infrastructure 3. Cluster Management 4. Service discovery and failure detection 5. Dockerizing Symfony Applications

Page 4: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

SOA and Microservices:7 days of app creation

Page 5: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 0 - In beginning was Word…

Page 6: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 1

www.example.com

Web server

Application

Database

Page 7: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 1. Evening

Page 8: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 2

www.example.com

Web server

Application Database

Cache

Page 9: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 3

www.example.com

Database

Application

Cache

Application

Cache

Web server

Page 10: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 4. Morning

DB Server Crash

Page 11: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 4. Night

www.example.com

DatabaseApplication

Cache

Application

Cache

Web server Database

Database

Database Cluster

Page 12: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 5

www.example.com

DatabaseApplication

Cache

Application

Cache

Database

Database

Database ClusterWeb server

Cache

Web server

Cache

Web server

Cache

Page 13: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 6

Cache

Application

CRUDUsers Authentication Notifications

API calls to 3-rd parties

Background processing

Page 14: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

A HA MOMENT

Page 15: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Day 7

www.example.com

Database

Database Cluster

Database Database

Users Service

Authenticationand

AuthorizationService

Notification Service

Crawler Service

Parser Service

Image Resizer Service

Report Generation

Service

Application Cluster

Web server

Web server

Web server

Web Servers Cluster

Cache

Cache

Cache Cluster

Page 16: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Core Idea

Process Component Microservice

Page 17: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Benefits1. Individual scalability 2. Language/Framework independent 3. Small in general

(easier for a developer to understand) 4. Independent development and

deploy process per service

Page 18: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Dockerized Infrastructure

Page 19: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Database

Database Cluster

Database Database

Users Service

Authenticationand

AuthorizationService

Notification Service

Crawler Service

Parser Service

Image Resizer Service

Report Generation

Service

Application Cluster

Cache

Cache

Cache Cluster

MQ

MQ Cluster

MQ

ES

ElasticSearch Cluster

ES ESNginx

Web Servers Cluster

Nginx Nginx

Services - are all about Containers

Page 20: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Software Delivery (before)

Page 21: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Software Delivery (before)

Page 22: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

The Game Changer

Page 23: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Software Delivery (now)

Page 24: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Software Delivery (now)

Page 25: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Software Delivery (now)

Page 26: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Dockerfile(DSL)

Docker Image

DockerContainer

App

App 2

App 3

1

2

3

Uniform Processing

Page 27: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Problems?

Page 28: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"
Page 29: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Where is my services?

Service Discovery

Page 30: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Tomcat10.0.1.17:8080

RabbitMQ10.0.1.171:5672

MongoDB10.0.1.253:27017

API10.0.1.11:80

Service Locator

10.0.1.17:8080 tomcat10.0.1.171:5672 rabbitmq10.0.1.253:27017 mongodb10.0.1.11:3306 api

Page 31: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Looks familiar?

Own DNS?

Page 32: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Solution

Consul by HashiCorp(consul.io)

Page 33: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Service Discovery

Service 4

Service 2

Service 3

Service 1

Service 1

Service 2

Service 3

Service 2

Page 34: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Service Discovery

Service 2

Service 2

Service 2

service2.service.consul

Page 35: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Service Discovery

DNS Masq Consul

External DNS

*.service.consul

Page 36: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Service Discovery

Page 37: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Cluster Management

Page 38: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Server 14 CPU & 16GB RAM

Server 28 CPU & 32GB RAM

Server 31 CPU & 8GB RAM

Server 4 2 CPU & 2GB RAM

Notification Service

API Service

Image Resizer4xCPU

Reporting Service2xRAM

Logger Service

User Service

Resources(servers)

Services(images)

Containers(running)

2x3x

10x

4x

1x1x

Page 39: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Cluster Management

• ECS & ECR (Amazon)• Kubernetes (Google)• Nomad (HashiCorp)• Mesos & Marathon (Apache)

Page 40: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Ansible

Page 41: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

hosts: webservers sudo: True tasks: - name: install nginx apt: name=nginx update_cache=yes

- name: copy nginx config file copy: src=files/nginx.conf dest=/etc/nginx/sites-available/default

- name: enable configuration file: > dest=/etc/nginx/sites-enabled/default src=/etc/nginx/sites-available/default state=link

- name: copy index.html template: > src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html mode=0644

- name: restart nginx service: name=nginx state=restarted

Ansible Playbooks

Page 42: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Symfony Appswith Docker

Page 43: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Symfony Apps with Docker

Application Code

Webserver

Database

Cache

PHP-FPM Supervisord

• PHP-FPM • Webserver • Database • Cache

Page 44: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Pitfalls with Docker

Page 45: Алексей Петров "Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible"

Questions?Oleksii PetrovSkelia Ukraine / ETwater Systems

skype: alexhelkar twitter: @alexhelkar email: [email protected]

Welcome to Kiev PHP User Group