Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and Ansible
Oleksii Petrov Skelia Ukraine / ETwater Systems skype: alexhelkar twitter: @alexhelkar email: [email protected]
1. What for the goat needs an accordion?
Agenda
Agenda (real)1. SOA and Microservices 2. Dockerized infrastructure 3. Cluster Management 4. Service discovery and failure detection 5. Dockerizing Symfony Applications
SOA and Microservices:7 days of app creation
Day 0 - In beginning was Word…
Day 1. Evening
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 scalability 2. Language/Framework independent 3. 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)
2x3x
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: alexhelkar twitter: @alexhelkar email: [email protected]
Welcome to Kiev PHP User Group