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

Post on 17-Feb-2017

4.760 views 1 download

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

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

Oleksii PetrovSkelia Ukraine / ETwater Systems

skype: alexhelkartwitter: @alexhelkaremail: alexhelkar@gmail.com

1. What for the goat needs an accordion?

Agenda

Agenda (real)1. SOA and Microservices2. Dockerized infrastructure3. Cluster Management4. Service discovery and failure detection5. Dockerizing Symfony Applications

SOA and Microservices:7 days of app creation

Day 0 - In beginning was Word…

Day 1

www.example.com

Web server

Application

Database

Day 1. Evening

Day 2

www.example.com

Web server

Application Database

Cache

Day 3

www.example.com

Database

Application

Cache

Application

Cache

Web server

Day 4. Morning

DB Server Crash

Day 4. Night

www.example.com

DatabaseApplication

Cache

Application

Cache

Web server Database

Database

Database Cluster

Day 5

www.example.com

DatabaseApplication

Cache

Application

Cache

Database

Database

Database ClusterWeb server

Cache

Web server

Cache

Web server

Cache

Day 6

Cache

Application

CRUDUsers Authentication Notifications

API calls to 3-rd parties

Background processing

A HA MOMENT

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

Core Idea

Process Component Microservice

Benefits1. Individual scalability2. Language/Framework independent3. Small in general

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

deploy process per service

Dockerized Infrastructure

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

Software Delivery (before)

Software Delivery (before)

The Game Changer

Software Delivery (now)

Software Delivery (now)

Software Delivery (now)

Dockerfile(DSL)

Docker Image

DockerContainer

App

App 2

App 3

1

2

3

Uniform Processing

Problems?

Where is my services?

Service Discovery

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

Looks familiar?

Own DNS?

Solution

Consul by HashiCorp(consul.io)

Service Discovery

Service 4

Service 2

Service 3

Service 1

Service 1

Service 2

Service 3

Service 2

Service Discovery

Service 2

Service 2

Service 2

service2.service.consul

Service Discovery

DNS Masq Consul

External DNS

*.service.consul

Service Discovery

Cluster Management

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)

2x

3x

10x

4x

1x1x

Cluster Management

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

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

Symfony Appswith Docker

Symfony Apps with Docker

Application Code

Webserver

Database

Cache

PHP-FPM Supervisord• PHP-FPM• Webserver• Database• Cache

Pitfalls with Docker

Questions?Oleksii PetrovSkelia Ukraine / ETwater Systems

skype: alexhelkartwitter: @alexhelkaremail: alexhelkar@gmail.com

Welcome to Kiev PHP User Group