Laravel, Docker,
Kubernetes
Local development and deployment
Welkom
Peter Mein
Lead Developer
Rapide Internet
Rens Reinders
Technisch directeur
Rapide Internet
Subjects
Containers
Docker
Docker-compose
Kubernetes
On each subject a will link back to Laravel
A step back, containers
1930-39 McLean Concept for Containers
1955 Clifford J. Rogers First containership is build
1966 Rotterdam First container is load of the SS
Fairbanks
1979 Unix v7 Introduction of chroot
2000 FreeBSD Introduction of Jails
2001 Linux Linux VServer, seperation of
resources
2008 LXC Introduction of
LinuXContainers
2013 Docker Introduction of Docker
2017 Kubernetes Kubernetes is matured is open
Goal
Flexibility in all layers of the deployment stack
App App App
Host
App App
Docker
What is a container
Linux containers, contain applications in a way that keep them isolated from the
host system that they run on.
Great! Lets build one
Let me explain the basic concepts
● Daemon
● Dockerfile
Dockerfile
FROM busybox:1.30
RUN mkdir test
WORKDIR test
RUN echo 'Hello World' > hello.txt
#EXPOSE 80
#COPY . /src
CMD ["cat", "hello.txt"]
We can now bundle our application in to a container!
How is this used for Laravel
- PHP
- Nginx or Apache
- Database
- Cache
Bundle your application into a package
What does this look like for lararel
Goal
App App App
Host
App App
Docker compose
Next goal?
We want to use multiple apps at the same time and let them interact with each
other.
Split up services into useful containers.
Don’t reinvent the wheel all over again.
Docker registry
Docker-compose
Spinning all containers up by hand in CLI is quite tedious.
Docker compose can help you orchestrate this beter.
** --link is deprecated,
docker run --name mysql -p 3306:3306 -d mysql
docker run --name php-fpm -p 9000:9000 -d php-fpm --link mysql:mysql
docker run --name docker-nginx -p 80:80 -d nginx --link php-fpm:php-fpm
tired of typing …..
How is used with Laravel?
- Spin up services you need for you current project
- Share a development environment
- Don’t worry about running on which platform
- Make sure your production and dev environment are the same
docker-compose.yml
The config file of weaving containers together
example
Local development tips
- Connecting to containers
- Running artisan commands
- File permissions
Final notes on docker compose
Don’t use this in production!
Docker-compose is getting out of fashion in favor a local k8s cluster
Goal
App App App
Host
App App
Kubernetes
Last goal
Our resources are limited and we can’t run all apps on one machine. So we need to
distribute our host.
App App App
Host
App App
Last goal
Our resources are limited and we can’t run all apps on one machine. So we need to
distribute our host.
App App App
Host
App App
Host
What is kubernetes
“Kubernetes is a portable, extensible open-source platform for managing
containerized workloads and services, that facilitates both declarative configuration
and automation”
Nodes
Concept in k8s
Pods - Run 1 or more containers
Deployment - Keeps pods running
Services - Used for networking inside a cluster
ConfigMap - Used for storing environment variables
Secret - Used for storing secret data (i.e. oauth-keys)
PersistentVolumeClaim - Used to allocate storage
and a lot more….
Declarative - a yaml file
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/etc/nginx/"
name: "nginx-conf"
volumes:
- name: "nginx-conf"
secret:
secretName: "nginx.conf"
Let me show you
Spin up the application
- Nginx
- PHP-fpm
- Service
On thing to consider don’t use local storage inside you application
Goal
App App App
Host
App App
Host
Dedicated vs cloud clusters
- Networking and load balancing is easy in the cloud but hard in a dedicated
cluster
- Storage requires extensive infrastructure (i.e. a Ceph cluster)
- Control your own hardware (add a gpu for example)
- GDPR
- Cost
- Hybrid solutions
Lets have some fun!
Load Balancer - Main used in cloud providers to get external ip’s
Replication - Scale up you deployment to accomodate more
load
Autoscalers - Let the cluster decide when to scale up!
Automation
Questions?
More
Helmsmen.io Rapide/Osso
- Managed dedicated clusters
- Managed cloud clusters
- Consult
- CI
- Training
Resources
I don’t want to write all containers
http://laradock.io/
I dont’ know where to get started on putting my Laravel app in K8s
https://github.com/markhilton/larakube
Local cluster for development
https://microk8s.io/
Local cluster for development
https://kubernetes.io/docs/setup/minikube/

Laravel, docker, kubernetes

  • 1.
  • 2.
    Welkom Peter Mein Lead Developer RapideInternet Rens Reinders Technisch directeur Rapide Internet
  • 3.
  • 4.
    A step back,containers 1930-39 McLean Concept for Containers 1955 Clifford J. Rogers First containership is build 1966 Rotterdam First container is load of the SS Fairbanks 1979 Unix v7 Introduction of chroot 2000 FreeBSD Introduction of Jails 2001 Linux Linux VServer, seperation of resources 2008 LXC Introduction of LinuXContainers 2013 Docker Introduction of Docker 2017 Kubernetes Kubernetes is matured is open
  • 5.
    Goal Flexibility in alllayers of the deployment stack App App App Host App App
  • 6.
  • 7.
    What is acontainer Linux containers, contain applications in a way that keep them isolated from the host system that they run on.
  • 9.
    Great! Lets buildone Let me explain the basic concepts ● Daemon ● Dockerfile
  • 10.
    Dockerfile FROM busybox:1.30 RUN mkdirtest WORKDIR test RUN echo 'Hello World' > hello.txt #EXPOSE 80 #COPY . /src CMD ["cat", "hello.txt"]
  • 11.
    We can nowbundle our application in to a container!
  • 12.
    How is thisused for Laravel - PHP - Nginx or Apache - Database - Cache Bundle your application into a package
  • 13.
    What does thislook like for lararel
  • 14.
  • 15.
  • 16.
    Next goal? We wantto use multiple apps at the same time and let them interact with each other. Split up services into useful containers. Don’t reinvent the wheel all over again.
  • 17.
  • 18.
    Docker-compose Spinning all containersup by hand in CLI is quite tedious. Docker compose can help you orchestrate this beter. ** --link is deprecated, docker run --name mysql -p 3306:3306 -d mysql docker run --name php-fpm -p 9000:9000 -d php-fpm --link mysql:mysql docker run --name docker-nginx -p 80:80 -d nginx --link php-fpm:php-fpm tired of typing …..
  • 19.
    How is usedwith Laravel? - Spin up services you need for you current project - Share a development environment - Don’t worry about running on which platform - Make sure your production and dev environment are the same
  • 20.
    docker-compose.yml The config fileof weaving containers together example
  • 21.
    Local development tips -Connecting to containers - Running artisan commands - File permissions
  • 22.
    Final notes ondocker compose Don’t use this in production! Docker-compose is getting out of fashion in favor a local k8s cluster
  • 23.
  • 24.
  • 25.
    Last goal Our resourcesare limited and we can’t run all apps on one machine. So we need to distribute our host. App App App Host App App
  • 26.
    Last goal Our resourcesare limited and we can’t run all apps on one machine. So we need to distribute our host. App App App Host App App Host
  • 27.
    What is kubernetes “Kubernetesis a portable, extensible open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation”
  • 28.
  • 29.
    Concept in k8s Pods- Run 1 or more containers Deployment - Keeps pods running Services - Used for networking inside a cluster ConfigMap - Used for storing environment variables Secret - Used for storing secret data (i.e. oauth-keys) PersistentVolumeClaim - Used to allocate storage and a lot more….
  • 30.
    Declarative - ayaml file apiVersion: v1 kind: Pod metadata: name: nginx labels: name: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 volumeMounts: - mountPath: "/etc/nginx/" name: "nginx-conf" volumes: - name: "nginx-conf" secret: secretName: "nginx.conf"
  • 31.
    Let me showyou Spin up the application - Nginx - PHP-fpm - Service On thing to consider don’t use local storage inside you application
  • 32.
  • 33.
    Dedicated vs cloudclusters - Networking and load balancing is easy in the cloud but hard in a dedicated cluster - Storage requires extensive infrastructure (i.e. a Ceph cluster) - Control your own hardware (add a gpu for example) - GDPR - Cost - Hybrid solutions
  • 34.
    Lets have somefun! Load Balancer - Main used in cloud providers to get external ip’s Replication - Scale up you deployment to accomodate more load Autoscalers - Let the cluster decide when to scale up! Automation
  • 35.
  • 36.
    More Helmsmen.io Rapide/Osso - Manageddedicated clusters - Managed cloud clusters - Consult - CI - Training
  • 37.
    Resources I don’t wantto write all containers http://laradock.io/ I dont’ know where to get started on putting my Laravel app in K8s https://github.com/markhilton/larakube Local cluster for development https://microk8s.io/ Local cluster for development https://kubernetes.io/docs/setup/minikube/

Editor's Notes

  • #11 Stappenplan docker file