Giter Club home page Giter Club logo

larakube's Introduction

Laravel

Things evolve faster than my commitment to this documentation, but may still be helpful...

Walk through deploying a Laravel application on auto scaled Kubernetes cluster.

Goal: Deploy Laravel PHP app that will auto scale based on average CPU utilization across cluster nodes.

Install Laravel with composer

composer global require "laravel/installer"

Create new Laravel project

composer create-project --prefer-dist laravel/laravel laravel-project

Local development

I have created docker-compose.yml with a typical infrastructure stack that includes:

  • MySQL (default database)
  • Redis (default cache engine)
  • Node (for auto compiling VUE components into app.js & css.js using webpack)

Linked following folders to Docker volumes:

  • MySQL data storage
  • Laravel vendors/
  • Laravel storage/
  • Laravel storage/public
  • Laravel node_modules

Therefore it's important to remember that while you work with this stack, the Laravel logs, compiled templates, cache files, vendor libraries, user uploads and application storage files, as well as MySQL database files will be saved in Docker volumes.

If you installed docker-compose already, simply run:

docker-compose up

and watch logs as Docker will pull all required stack images and provision application environment:

  • install required Laravel storage folders
  • run pending database migrations
  • run composer to install all vendor libraries
  • run node to install all dependencies to compile: app.js & app.css

Both composer and node container will remain running. Node will monitor (watch) for changes in resourse/js/ files to re-compile them on the fly.

Composer will remain running if you need to install additional vendor libraries, simply enter composer container shell with and for example install Redis support libs:

docker exec -ti composer bash
composer require predis/predis
composer require laravel/horizon

Node container:

docker exec -ti node bash
npm install

Laravel Horizon is a great package to manage Laravel queues with Redis.

Docker

For the purpose of this demo I've built a public Docker image and pushed to my account. Dockerfile adds Laravel app into a lightweight alpine image.

build application docker image

docker build -t crunchgeek/laravel-project .

push image to the repository

docker push crunchgeek/laravel-project

Kubernetes

Having to work with Kubernetes for the last year I've got some experience with both Google Cloud and AWS services providers.

I installed K8s on AWS using KOPS and do not recommend this for production workloads. I run into multiple issues around I/O performance with Docker overlay. AWS EKS does not appeal to me like GKE. Google K8s is real hands off managed master node, with easy upgrades and it ended up as my go to solution.

I also learned about Helm, Kubernetes package manager. So once you get your K8s cluster up on GKE I recommend this tutorial to install Helm.

test dry run helm chart

helm install --name laravel-labs --dry-run --debug ./laravel

install or upgrade current helm chart

helm upgrade laravel-labs ./laravel -i

delete helm chart

helm del --purge laravel-labs

That's it! Now the infrastructure will auto adjust itself to the app resources demand.

Ingress / Load Balancing

Every time you deploy a completely independent application on Kubernetes exposed to the public network - it will probably come with a Load Balancer service. This may be costly if you have to deploy several of them.

Instead better solution is to use Nginx Ingress Helm Chart with a single Load Balancer and IP address. You can deploy as many new services as you need and use Ingress to route the traffic to a specific app.

SSL support

The easiest way to deploy SSL protected application is to use Cert Manager Helm Chart, which will provision SSL certificates using free Let's Encrypt service.

Deploying SSL protected sites is as simple as adding a single line in your ingress.yaml

larakube's People

Contributors

markhilton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

larakube's Issues

App secrets not being loaded by laravel

Hello,

I've been playing around this and actually added a secret for the laravel app settings (.env file), on Laravel 5.7 I'm not being able to use the env settings on the laravel.

If I enter the php-fpm container and run echo $MYSQL_USER I get homestead (correct, is what I passed in the docker variables) but when I run php artisan migrate for example it uses the forge user (which is the default when no variable is found).
If I create a .env file it uses that file correctly. having this said, how can I get this to work with the docker environment variables?

Why compose and kubernetes?

Hi,

I have been studying this repo and was wondering why you have both compose and kubernetes together in here?

If its just for local dev purposes wouldnt it make sense to do local development within the kubernetes so you are as close to prod's environment as you can get?

Cheers.

SSL

Hi, i have a question. how i can implement ssl like lets encrypt?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.