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

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]

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

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 PetrovSkelia Ukraine / ETwater Systems

skype: alexhelkartwitter: @alexhelkaremail: [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 Microservices2. Dockerized infrastructure3. Cluster Management4. Service discovery and failure detection5. 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 scalability2. Language/Framework independent3. 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)

2x

3x

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: alexhelkartwitter: @alexhelkaremail: [email protected]

Welcome to Kiev PHP User Group