SlideShare a Scribd company logo
1 of 28
Download to read offline
Adventures with Laravel and Kubernetes
at superbalist.com
William Stewart
 zatech


 zoidbergwill basically everywhere
1 / 28
Intro
Who am I?
What do I do?
2 / 28
Overview
Docker
What is Docker?
Why do we use it?
Kubernetes
What is Kubernetes?
Why do we use it?
Some extra tools
A quick demo
War stories
Logging
Signal propagation
Long running processes
Schema changes
3 / 28
Docker
4 / 28
What is Docker?
5 / 28
How does it help?
Language agnostic build artifact
FROM composer:alpine
COPY composer.json composer.lock /app
RUN composer install --ansi --no-interaction --no-scripts --no-dev --no-autoloader
COPY . /app
RUN composer install
or
FROM node:alpine
COPY package.json /app
RUN npm install
COPY . /app
6 / 28
How does it help?
No more "works on my machine", because they're the same images locally and on production
Smaller shippable artifacts than full machine images, and easier to independently scale components
A lot of useful services already in the Docker registry:
MySQL
Redis
Memcached
Elastic Search
RabbitMQ
7 / 28
Running Docker in production
8 / 28
How does it help?
- Container hosting
- Con g changes
- Supervision
- Monitoring
- Rolling deployments
- Networking / Service discovery
- and more...
9 / 28
Automate the boring stu f
“Automation is a force multiplier, not a panacea”
Value of automation
Consistency
Extensibility
MTTR (Mean Time To Repair)
Faster non-repair actions
Time savings
Dan Luu's Notes on Google's Site Reliability Engineering book
10 / 28
What is Kubernetes?
an open source container
cluster manager
11 / 28
How does it help?
Faster/smarter builds than a .tar.gz
Reliable rolling updates (safer than a symlink swap)
Similar build/deploy scripts for all languages and services
Autoscaling (based on CPU usage)
Fine-grained healthchecking
Accurate resource monitoring and better usage
12 / 28
Helps us to easily move towards SOA,
Easily start new projects in any language, that can rely on the same service discovery (using DNS)
Discovery via DNS (curl http://elasticsearch/) or automatically set Kubernetes environment
variables (env('ELASTICSEARCH_SERVICE_HOST')), that balances load over a collection of Elastic Search
clients, all automatically updated by Kubernetes.
A huge collection of base Docker les on hub.docker.com and quay.io
13 / 28
Avoid "works on my machine" issues
Accurately replicate most of our production environment locally (other than a mocked Google Loadbalancer)
Using:
minikube, which behaves like a single-node Kubernetes cluster
docker, moving towards rocker, to better utilise global Composer/NPM cache
NFS, to allow faster feedback when developing
some bash glue
14 / 28
Easily implement monitoring, logging, and LetsEncrypt
Simply implement metrics monitoring and LetsEncrypt using Kubernetes annotations:
annotations:
prometheus.io/port: "9150"
prometheus.io/scrape: "true"
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: gce
kubernetes.io/tls-acme: "true"
name: general-ingress
spec:
rules:
- host: tasks.zoidbergwill.com
http:
paths:
- backend:
serviceName: tasks-app
servicePort: 80
path: /
tls:
- hosts:
- tasks.zoidbergwill.com
secretName: tasks-tls
15 / 28
Demo tools
Minikube
Rocker
Kube-lego
16 / 28
DEMO
DEMO
17 / 28
War stories
18 / 28
Logging
Logging to a le worked great on compute engine with uentd
Gcloud Stackdriver Logging is pretty amazing, but with container engine it wants stdout
± ag log tasks/config/app.php
112: | Logging Configuration
115: | Here you may configure the log settings for your application. Out of
116: | the box, Laravel uses the Monolog PHP logging library. This gives
117: | you a variety of powerful log handlers / formatters to utilize.
119: | Available Settings: "single", "daily", "syslog", "errorlog"
123: 'log' => env('APP_LOG', 'single'),
125: 'log_level' => env('APP_LOG_LEVEL', 'debug'),
212: 'Log' => IlluminateSupportFacadesLog::class,
19 / 28
Logging Monolog/Laravel options
single/daily le:
doesn't go to stdout and get consumed by fluentd-cloud-logging
syslog:
another dependency, and we'd need to install syslog and tail it, or talk to an external syslog daemon
errorlog:
php-fpm logs have a pre x you can't get rid of
Bubbling them to the nginx container also has a gross pre x and means you can't separate the logs for each container
20 / 28
Upstream php images also do some gross logging stu f
FROM php:7-fpm
[global]
error_log = /proc/self/fd/2
[www]
access.log = /proc/self/fd/2
Access logs are junk for Laravel:
:: - 07/Feb/2017:13:57:57 +0000 "GET /index.php" 200 (x 1337)
error_log can be pretty crap too:
[07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: "NOTICE: PHP message: Array"
[07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: "("
[07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: " [6] => 363"
[07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: ")"
[07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: ""
21 / 28
Going full circle
Let's try single again:
> cat entrypoint.sh
# Tail a log file, and background that process
tail -f /var/www/html/storage/logs/laravel.log &
# Now run the more important piece
php-fpm7
22 / 28
Signal propagation
Linux relies on PID 1 doing important stuff, that an init system does
Most Docker entrypoints use exec to become the main process, but this kills anything running in the script.
Shells (like bash) don't propagate signals, like SIGTERM or SIGQUIT, which messes with graceful shutting down.
When a pod dies:
PID 1 in the container gets a SIGTERM and given a grace period (default: 30s) to shutdown by default
Once the grace period has expired then a SIGKILL signal is sent
dumb-init and lifecycle hooks to the rescue!
dumb-init wraps your ENTRYPOINT shell script and makes sure signals propagate to child processes
lifecycle:
preStop:
exec:
# SIGTERM triggers a quick exit; gracefully terminate instead
command: ["/usr/sbin/nginx","-s","quit"] # or php artisan queue:restart
23 / 28
Cron
If you run plain old cron it runs processes in a separate env, so we dump our Kubernetes environment for phpdotenv to
read:
# Cron is a bastard that has sub processes with different env vars.
env > .env
sed -i -e "s/=(.*)$/="1"/g" .env
24 / 28
Long running processes
The max "grace period" for a pod is 5 minutes.
Easy steps in the right direction:
Break tasks up as small as possible
Put most tasks on queues
Use Kubernetes "Jobs" when forced to
25 / 28
Database migrations
Three step DB Migrations
Migrating before starting a rolling update
26 / 28
Superbalist.com and Takealot.com are hiring!!!
Source
https://github.com/zoidbergwill/kubernetes-php-examples
Slides: zoidergwill.github.io/presentations/2017/kubernetes-php/
Links on the next slide!
27 / 28
Links
O'Reilly's Site Reliability Engineering: How Google Runs Production Systems Amazon
Dan Luu's notes are good too
Borg, Omega, and Kubernetes Lessons learned from three container-management systems over a decade. Essay
kubernetes-dashboard
Cloud Native Computing Foundation
Kubernetes-Anywhere: An of cial Kubernetes repo with some documentation on running Kubernetes with Docker
for Mac beta
minikube: The of cial Go binary for running a simpler local cluster.
awesome-kubernetes list on GitHub, cuz it has some neat things.
Docker and the PID 1 reaping problem
Containers really are the future
28 / 28

More Related Content

What's hot

Automatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes ClusterAutomatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes ClusterHungWei Chiu
 
Monitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMonitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMartin Etmajer
 
KubeCon EU 2016: Multi-Tenant Kubernetes
KubeCon EU 2016: Multi-Tenant KubernetesKubeCon EU 2016: Multi-Tenant Kubernetes
KubeCon EU 2016: Multi-Tenant KubernetesKubeAcademy
 
Docker Platform Internals: Taking runtimes and image creation to the next lev...
Docker Platform Internals: Taking runtimes and image creation to the next lev...Docker Platform Internals: Taking runtimes and image creation to the next lev...
Docker Platform Internals: Taking runtimes and image creation to the next lev...Docker, Inc.
 
Tales of Training: Scaling CodeLabs with Swarm Mode and Docker-Compose
Tales of Training: Scaling CodeLabs with Swarm Mode and Docker-ComposeTales of Training: Scaling CodeLabs with Swarm Mode and Docker-Compose
Tales of Training: Scaling CodeLabs with Swarm Mode and Docker-ComposeDocker, Inc.
 
Deep dive in container service discovery
Deep dive in container service discoveryDeep dive in container service discovery
Deep dive in container service discoveryDocker, Inc.
 
Zero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetesZero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetesArjan Schaaf
 
What’s New in Docker - Victor Vieux, Docker
What’s New in Docker - Victor Vieux, DockerWhat’s New in Docker - Victor Vieux, Docker
What’s New in Docker - Victor Vieux, DockerDocker, Inc.
 
LinuxKit Deep Dive
LinuxKit Deep DiveLinuxKit Deep Dive
LinuxKit Deep DiveDocker, Inc.
 
Kubernetes and Hybrid Deployments
Kubernetes and Hybrid DeploymentsKubernetes and Hybrid Deployments
Kubernetes and Hybrid DeploymentsSandeep Parikh
 
Moby and Kubernetes entitlements
Moby and Kubernetes entitlements Moby and Kubernetes entitlements
Moby and Kubernetes entitlements Docker, Inc.
 
Beyond Ingresses - Better Traffic Management in Kubernetes
Beyond Ingresses - Better Traffic Management in KubernetesBeyond Ingresses - Better Traffic Management in Kubernetes
Beyond Ingresses - Better Traffic Management in KubernetesMark McBride
 
Effective Data Pipelines with Docker & Jenkins - Brian Donaldson
Effective Data Pipelines with Docker & Jenkins - Brian DonaldsonEffective Data Pipelines with Docker & Jenkins - Brian Donaldson
Effective Data Pipelines with Docker & Jenkins - Brian DonaldsonDocker, Inc.
 
Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Weaveworks
 
Understanding Kubernetes
Understanding KubernetesUnderstanding Kubernetes
Understanding KubernetesTu Pham
 
Docker Meetup 08 03-2016
Docker Meetup 08 03-2016Docker Meetup 08 03-2016
Docker Meetup 08 03-2016Docker
 
Kubelet with no Kubernetes Masters | DevNation Tech Talk
Kubelet with no Kubernetes Masters | DevNation Tech TalkKubelet with no Kubernetes Masters | DevNation Tech Talk
Kubelet with no Kubernetes Masters | DevNation Tech TalkRed Hat Developers
 
Developing Microservices Directly in AKS/Kubernetes
Developing Microservices Directly in AKS/KubernetesDeveloping Microservices Directly in AKS/Kubernetes
Developing Microservices Directly in AKS/KubernetesChakradhar Rao Jonagam
 

What's hot (20)

Automatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes ClusterAutomatically Renew Certificated In Your Kubernetes Cluster
Automatically Renew Certificated In Your Kubernetes Cluster
 
Monitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMonitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on Kubernetes
 
KubeCon EU 2016: Multi-Tenant Kubernetes
KubeCon EU 2016: Multi-Tenant KubernetesKubeCon EU 2016: Multi-Tenant Kubernetes
KubeCon EU 2016: Multi-Tenant Kubernetes
 
Docker Platform Internals: Taking runtimes and image creation to the next lev...
Docker Platform Internals: Taking runtimes and image creation to the next lev...Docker Platform Internals: Taking runtimes and image creation to the next lev...
Docker Platform Internals: Taking runtimes and image creation to the next lev...
 
Tales of Training: Scaling CodeLabs with Swarm Mode and Docker-Compose
Tales of Training: Scaling CodeLabs with Swarm Mode and Docker-ComposeTales of Training: Scaling CodeLabs with Swarm Mode and Docker-Compose
Tales of Training: Scaling CodeLabs with Swarm Mode and Docker-Compose
 
Deep dive in container service discovery
Deep dive in container service discoveryDeep dive in container service discovery
Deep dive in container service discovery
 
Zero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetesZero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetes
 
What’s New in Docker - Victor Vieux, Docker
What’s New in Docker - Victor Vieux, DockerWhat’s New in Docker - Victor Vieux, Docker
What’s New in Docker - Victor Vieux, Docker
 
LinuxKit Deep Dive
LinuxKit Deep DiveLinuxKit Deep Dive
LinuxKit Deep Dive
 
Kubernetes and Hybrid Deployments
Kubernetes and Hybrid DeploymentsKubernetes and Hybrid Deployments
Kubernetes and Hybrid Deployments
 
Moby and Kubernetes entitlements
Moby and Kubernetes entitlements Moby and Kubernetes entitlements
Moby and Kubernetes entitlements
 
Beyond Ingresses - Better Traffic Management in Kubernetes
Beyond Ingresses - Better Traffic Management in KubernetesBeyond Ingresses - Better Traffic Management in Kubernetes
Beyond Ingresses - Better Traffic Management in Kubernetes
 
My kubernetes toolkit
My kubernetes toolkitMy kubernetes toolkit
My kubernetes toolkit
 
From Code to Kubernetes
From Code to KubernetesFrom Code to Kubernetes
From Code to Kubernetes
 
Effective Data Pipelines with Docker & Jenkins - Brian Donaldson
Effective Data Pipelines with Docker & Jenkins - Brian DonaldsonEffective Data Pipelines with Docker & Jenkins - Brian Donaldson
Effective Data Pipelines with Docker & Jenkins - Brian Donaldson
 
Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes
 
Understanding Kubernetes
Understanding KubernetesUnderstanding Kubernetes
Understanding Kubernetes
 
Docker Meetup 08 03-2016
Docker Meetup 08 03-2016Docker Meetup 08 03-2016
Docker Meetup 08 03-2016
 
Kubelet with no Kubernetes Masters | DevNation Tech Talk
Kubelet with no Kubernetes Masters | DevNation Tech TalkKubelet with no Kubernetes Masters | DevNation Tech Talk
Kubelet with no Kubernetes Masters | DevNation Tech Talk
 
Developing Microservices Directly in AKS/Kubernetes
Developing Microservices Directly in AKS/KubernetesDeveloping Microservices Directly in AKS/Kubernetes
Developing Microservices Directly in AKS/Kubernetes
 

Viewers also liked

Kubernetes - Starting with 1.2
Kubernetes  - Starting with 1.2Kubernetes  - Starting with 1.2
Kubernetes - Starting with 1.2William Stewart
 
Microservices at scale with docker and kubernetes - AMS JUG 2017
Microservices at scale with docker and kubernetes - AMS JUG 2017Microservices at scale with docker and kubernetes - AMS JUG 2017
Microservices at scale with docker and kubernetes - AMS JUG 2017Arjen Wassink
 
Welcome talk for Moscow Kubernetes Meetup 1
Welcome talk for Moscow Kubernetes Meetup 1Welcome talk for Moscow Kubernetes Meetup 1
Welcome talk for Moscow Kubernetes Meetup 1MoscowKubernetes
 
Deploy your favorite apps on Kubernetes
Deploy your favorite apps on KubernetesDeploy your favorite apps on Kubernetes
Deploy your favorite apps on KubernetesAdnan Abdulhussein
 
GitLab, Prometheus и Grafana с Kubernetes
GitLab, Prometheus и Grafana с KubernetesGitLab, Prometheus и Grafana с Kubernetes
GitLab, Prometheus и Grafana с KubernetesVictor Login
 
Teaching Apache Spark Clusters to Manage Their Workers Elastically: Spark Sum...
Teaching Apache Spark Clusters to Manage Their Workers Elastically: Spark Sum...Teaching Apache Spark Clusters to Manage Their Workers Elastically: Spark Sum...
Teaching Apache Spark Clusters to Manage Their Workers Elastically: Spark Sum...Spark Summit
 
Deploying deep learning models with Docker and Kubernetes
Deploying deep learning models with Docker and KubernetesDeploying deep learning models with Docker and Kubernetes
Deploying deep learning models with Docker and KubernetesPetteriTeikariPhD
 
RackN DevOps meetup NYC
RackN DevOps meetup NYCRackN DevOps meetup NYC
RackN DevOps meetup NYCBob Sokol
 
Net core, mssql, container und kubernetes
Net core, mssql, container und kubernetesNet core, mssql, container und kubernetes
Net core, mssql, container und kubernetesThomas Fricke
 
Opening: builderscon tokyo 2016
Opening: builderscon tokyo 2016Opening: builderscon tokyo 2016
Opening: builderscon tokyo 2016lestrrat
 
Microservices summit talk 1/31
Microservices summit talk   1/31Microservices summit talk   1/31
Microservices summit talk 1/31Varun Talwar
 
Keeping up with Tech
Keeping up with Tech Keeping up with Tech
Keeping up with Tech Elana Krasner
 
Ростислав Фридман: “Kubernetes как средство управления микросервисами"
Ростислав Фридман: “Kubernetes как средство управления микросервисами"Ростислав Фридман: “Kubernetes как средство управления микросервисами"
Ростислав Фридман: “Kubernetes как средство управления микросервисами"Provectus
 
Docker Containers in Azure
Docker Containers in AzureDocker Containers in Azure
Docker Containers in AzureAarno Aukia
 
Kubernetes as Orchestrator for A10 Lightning Controller
Kubernetes as Orchestrator for A10 Lightning ControllerKubernetes as Orchestrator for A10 Lightning Controller
Kubernetes as Orchestrator for A10 Lightning ControllerAkshay Mathur
 
Google Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKEGoogle Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKESimon Su
 
Kubernetes API - deep dive into the kube-apiserver
Kubernetes API - deep dive into the kube-apiserverKubernetes API - deep dive into the kube-apiserver
Kubernetes API - deep dive into the kube-apiserverStefan Schimanski
 
Bangalore Container Conference - Sponsor Deck
Bangalore Container Conference - Sponsor DeckBangalore Container Conference - Sponsor Deck
Bangalore Container Conference - Sponsor DeckCodeOps Technologies LLP
 
Running Docker in Production - The Good, the Bad and The Ugly
Running Docker in Production - The Good, the Bad and The UglyRunning Docker in Production - The Good, the Bad and The Ugly
Running Docker in Production - The Good, the Bad and The UglyKontena, Inc.
 
Introduction to container mangement
Introduction to container mangementIntroduction to container mangement
Introduction to container mangementMartin Marcher
 

Viewers also liked (20)

Kubernetes - Starting with 1.2
Kubernetes  - Starting with 1.2Kubernetes  - Starting with 1.2
Kubernetes - Starting with 1.2
 
Microservices at scale with docker and kubernetes - AMS JUG 2017
Microservices at scale with docker and kubernetes - AMS JUG 2017Microservices at scale with docker and kubernetes - AMS JUG 2017
Microservices at scale with docker and kubernetes - AMS JUG 2017
 
Welcome talk for Moscow Kubernetes Meetup 1
Welcome talk for Moscow Kubernetes Meetup 1Welcome talk for Moscow Kubernetes Meetup 1
Welcome talk for Moscow Kubernetes Meetup 1
 
Deploy your favorite apps on Kubernetes
Deploy your favorite apps on KubernetesDeploy your favorite apps on Kubernetes
Deploy your favorite apps on Kubernetes
 
GitLab, Prometheus и Grafana с Kubernetes
GitLab, Prometheus и Grafana с KubernetesGitLab, Prometheus и Grafana с Kubernetes
GitLab, Prometheus и Grafana с Kubernetes
 
Teaching Apache Spark Clusters to Manage Their Workers Elastically: Spark Sum...
Teaching Apache Spark Clusters to Manage Their Workers Elastically: Spark Sum...Teaching Apache Spark Clusters to Manage Their Workers Elastically: Spark Sum...
Teaching Apache Spark Clusters to Manage Their Workers Elastically: Spark Sum...
 
Deploying deep learning models with Docker and Kubernetes
Deploying deep learning models with Docker and KubernetesDeploying deep learning models with Docker and Kubernetes
Deploying deep learning models with Docker and Kubernetes
 
RackN DevOps meetup NYC
RackN DevOps meetup NYCRackN DevOps meetup NYC
RackN DevOps meetup NYC
 
Net core, mssql, container und kubernetes
Net core, mssql, container und kubernetesNet core, mssql, container und kubernetes
Net core, mssql, container und kubernetes
 
Opening: builderscon tokyo 2016
Opening: builderscon tokyo 2016Opening: builderscon tokyo 2016
Opening: builderscon tokyo 2016
 
Microservices summit talk 1/31
Microservices summit talk   1/31Microservices summit talk   1/31
Microservices summit talk 1/31
 
Keeping up with Tech
Keeping up with Tech Keeping up with Tech
Keeping up with Tech
 
Ростислав Фридман: “Kubernetes как средство управления микросервисами"
Ростислав Фридман: “Kubernetes как средство управления микросервисами"Ростислав Фридман: “Kubernetes как средство управления микросервисами"
Ростислав Фридман: “Kubernetes как средство управления микросервисами"
 
Docker Containers in Azure
Docker Containers in AzureDocker Containers in Azure
Docker Containers in Azure
 
Kubernetes as Orchestrator for A10 Lightning Controller
Kubernetes as Orchestrator for A10 Lightning ControllerKubernetes as Orchestrator for A10 Lightning Controller
Kubernetes as Orchestrator for A10 Lightning Controller
 
Google Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKEGoogle Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKE
 
Kubernetes API - deep dive into the kube-apiserver
Kubernetes API - deep dive into the kube-apiserverKubernetes API - deep dive into the kube-apiserver
Kubernetes API - deep dive into the kube-apiserver
 
Bangalore Container Conference - Sponsor Deck
Bangalore Container Conference - Sponsor DeckBangalore Container Conference - Sponsor Deck
Bangalore Container Conference - Sponsor Deck
 
Running Docker in Production - The Good, the Bad and The Ugly
Running Docker in Production - The Good, the Bad and The UglyRunning Docker in Production - The Good, the Bad and The Ugly
Running Docker in Production - The Good, the Bad and The Ugly
 
Introduction to container mangement
Introduction to container mangementIntroduction to container mangement
Introduction to container mangement
 

Similar to Kubernetes laravel and kubernetes

Kubernetes for the PHP developer
Kubernetes for the PHP developerKubernetes for the PHP developer
Kubernetes for the PHP developerPaul Czarkowski
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...Codemotion
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014Carlo Bonamico
 
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...Puppet
 
Containers, Docker, and Microservices: the Terrific Trio
Containers, Docker, and Microservices: the Terrific TrioContainers, Docker, and Microservices: the Terrific Trio
Containers, Docker, and Microservices: the Terrific TrioJérôme Petazzoni
 
Web Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the CloudWeb Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the CloudMarkus Knauer
 
Scaling docker with kubernetes
Scaling docker with kubernetesScaling docker with kubernetes
Scaling docker with kubernetesLiran Cohen
 
Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant Ricardo Amaro
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1Hajime Tazaki
 
A DevOps guide to Kubernetes
A DevOps guide to KubernetesA DevOps guide to Kubernetes
A DevOps guide to KubernetesPaul Czarkowski
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3kognate
 
Advanced microservices with .Net
Advanced microservices with .NetAdvanced microservices with .Net
Advanced microservices with .NetDon Schenck
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Jérôme Petazzoni
 

Similar to Kubernetes laravel and kubernetes (20)

Kubernetes for the PHP developer
Kubernetes for the PHP developerKubernetes for the PHP developer
Kubernetes for the PHP developer
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014
 
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
 
Dockers zero to hero
Dockers zero to heroDockers zero to hero
Dockers zero to hero
 
Containers, Docker, and Microservices: the Terrific Trio
Containers, Docker, and Microservices: the Terrific TrioContainers, Docker, and Microservices: the Terrific Trio
Containers, Docker, and Microservices: the Terrific Trio
 
Web Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the CloudWeb Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the Cloud
 
Scaling docker with kubernetes
Scaling docker with kubernetesScaling docker with kubernetes
Scaling docker with kubernetes
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant
 
One-Man Ops
One-Man OpsOne-Man Ops
One-Man Ops
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1
 
Kubernetes 101 for_penetration_testers_-_null_mumbai
Kubernetes 101 for_penetration_testers_-_null_mumbaiKubernetes 101 for_penetration_testers_-_null_mumbai
Kubernetes 101 for_penetration_testers_-_null_mumbai
 
A DevOps guide to Kubernetes
A DevOps guide to KubernetesA DevOps guide to Kubernetes
A DevOps guide to Kubernetes
 
kubernetes for beginners
kubernetes for beginnerskubernetes for beginners
kubernetes for beginners
 
Devopstore
DevopstoreDevopstore
Devopstore
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 
Docker
DockerDocker
Docker
 
Advanced microservices with .Net
Advanced microservices with .NetAdvanced microservices with .Net
Advanced microservices with .Net
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...
 

Recently uploaded

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 

Recently uploaded (20)

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 

Kubernetes laravel and kubernetes

  • 1. Adventures with Laravel and Kubernetes at superbalist.com William Stewart  zatech    zoidbergwill basically everywhere 1 / 28
  • 2. Intro Who am I? What do I do? 2 / 28
  • 3. Overview Docker What is Docker? Why do we use it? Kubernetes What is Kubernetes? Why do we use it? Some extra tools A quick demo War stories Logging Signal propagation Long running processes Schema changes 3 / 28
  • 6. How does it help? Language agnostic build artifact FROM composer:alpine COPY composer.json composer.lock /app RUN composer install --ansi --no-interaction --no-scripts --no-dev --no-autoloader COPY . /app RUN composer install or FROM node:alpine COPY package.json /app RUN npm install COPY . /app 6 / 28
  • 7. How does it help? No more "works on my machine", because they're the same images locally and on production Smaller shippable artifacts than full machine images, and easier to independently scale components A lot of useful services already in the Docker registry: MySQL Redis Memcached Elastic Search RabbitMQ 7 / 28
  • 8. Running Docker in production 8 / 28
  • 9. How does it help? - Container hosting - Con g changes - Supervision - Monitoring - Rolling deployments - Networking / Service discovery - and more... 9 / 28
  • 10. Automate the boring stu f “Automation is a force multiplier, not a panacea” Value of automation Consistency Extensibility MTTR (Mean Time To Repair) Faster non-repair actions Time savings Dan Luu's Notes on Google's Site Reliability Engineering book 10 / 28
  • 11. What is Kubernetes? an open source container cluster manager 11 / 28
  • 12. How does it help? Faster/smarter builds than a .tar.gz Reliable rolling updates (safer than a symlink swap) Similar build/deploy scripts for all languages and services Autoscaling (based on CPU usage) Fine-grained healthchecking Accurate resource monitoring and better usage 12 / 28
  • 13. Helps us to easily move towards SOA, Easily start new projects in any language, that can rely on the same service discovery (using DNS) Discovery via DNS (curl http://elasticsearch/) or automatically set Kubernetes environment variables (env('ELASTICSEARCH_SERVICE_HOST')), that balances load over a collection of Elastic Search clients, all automatically updated by Kubernetes. A huge collection of base Docker les on hub.docker.com and quay.io 13 / 28
  • 14. Avoid "works on my machine" issues Accurately replicate most of our production environment locally (other than a mocked Google Loadbalancer) Using: minikube, which behaves like a single-node Kubernetes cluster docker, moving towards rocker, to better utilise global Composer/NPM cache NFS, to allow faster feedback when developing some bash glue 14 / 28
  • 15. Easily implement monitoring, logging, and LetsEncrypt Simply implement metrics monitoring and LetsEncrypt using Kubernetes annotations: annotations: prometheus.io/port: "9150" prometheus.io/scrape: "true" apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: kubernetes.io/ingress.class: gce kubernetes.io/tls-acme: "true" name: general-ingress spec: rules: - host: tasks.zoidbergwill.com http: paths: - backend: serviceName: tasks-app servicePort: 80 path: / tls: - hosts: - tasks.zoidbergwill.com secretName: tasks-tls 15 / 28
  • 19. Logging Logging to a le worked great on compute engine with uentd Gcloud Stackdriver Logging is pretty amazing, but with container engine it wants stdout ± ag log tasks/config/app.php 112: | Logging Configuration 115: | Here you may configure the log settings for your application. Out of 116: | the box, Laravel uses the Monolog PHP logging library. This gives 117: | you a variety of powerful log handlers / formatters to utilize. 119: | Available Settings: "single", "daily", "syslog", "errorlog" 123: 'log' => env('APP_LOG', 'single'), 125: 'log_level' => env('APP_LOG_LEVEL', 'debug'), 212: 'Log' => IlluminateSupportFacadesLog::class, 19 / 28
  • 20. Logging Monolog/Laravel options single/daily le: doesn't go to stdout and get consumed by fluentd-cloud-logging syslog: another dependency, and we'd need to install syslog and tail it, or talk to an external syslog daemon errorlog: php-fpm logs have a pre x you can't get rid of Bubbling them to the nginx container also has a gross pre x and means you can't separate the logs for each container 20 / 28
  • 21. Upstream php images also do some gross logging stu f FROM php:7-fpm [global] error_log = /proc/self/fd/2 [www] access.log = /proc/self/fd/2 Access logs are junk for Laravel: :: - 07/Feb/2017:13:57:57 +0000 "GET /index.php" 200 (x 1337) error_log can be pretty crap too: [07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: "NOTICE: PHP message: Array" [07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: "(" [07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: " [6] => 363" [07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: ")" [07-Feb-2015 11:46:44] WARNING: [pool www] child 32465 said into stderr: "" 21 / 28
  • 22. Going full circle Let's try single again: > cat entrypoint.sh # Tail a log file, and background that process tail -f /var/www/html/storage/logs/laravel.log & # Now run the more important piece php-fpm7 22 / 28
  • 23. Signal propagation Linux relies on PID 1 doing important stuff, that an init system does Most Docker entrypoints use exec to become the main process, but this kills anything running in the script. Shells (like bash) don't propagate signals, like SIGTERM or SIGQUIT, which messes with graceful shutting down. When a pod dies: PID 1 in the container gets a SIGTERM and given a grace period (default: 30s) to shutdown by default Once the grace period has expired then a SIGKILL signal is sent dumb-init and lifecycle hooks to the rescue! dumb-init wraps your ENTRYPOINT shell script and makes sure signals propagate to child processes lifecycle: preStop: exec: # SIGTERM triggers a quick exit; gracefully terminate instead command: ["/usr/sbin/nginx","-s","quit"] # or php artisan queue:restart 23 / 28
  • 24. Cron If you run plain old cron it runs processes in a separate env, so we dump our Kubernetes environment for phpdotenv to read: # Cron is a bastard that has sub processes with different env vars. env > .env sed -i -e "s/=(.*)$/="1"/g" .env 24 / 28
  • 25. Long running processes The max "grace period" for a pod is 5 minutes. Easy steps in the right direction: Break tasks up as small as possible Put most tasks on queues Use Kubernetes "Jobs" when forced to 25 / 28
  • 26. Database migrations Three step DB Migrations Migrating before starting a rolling update 26 / 28
  • 27. Superbalist.com and Takealot.com are hiring!!! Source https://github.com/zoidbergwill/kubernetes-php-examples Slides: zoidergwill.github.io/presentations/2017/kubernetes-php/ Links on the next slide! 27 / 28
  • 28. Links O'Reilly's Site Reliability Engineering: How Google Runs Production Systems Amazon Dan Luu's notes are good too Borg, Omega, and Kubernetes Lessons learned from three container-management systems over a decade. Essay kubernetes-dashboard Cloud Native Computing Foundation Kubernetes-Anywhere: An of cial Kubernetes repo with some documentation on running Kubernetes with Docker for Mac beta minikube: The of cial Go binary for running a simpler local cluster. awesome-kubernetes list on GitHub, cuz it has some neat things. Docker and the PID 1 reaping problem Containers really are the future 28 / 28