Files
laravel-docker-k8s/readme.md
2018-05-10 18:16:51 +02:00

3.7 KiB
Executable File

laravel-docker-kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. I'm using this personal repository as an attempt to package and run Laravel using Docker and deploy it on Kubernetes. In this tutorial I'm using Minikube, which is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day. This repository is a copy of the laravel-docker-k8s from nahidulhasan link, but since I'm going to adjust it heavily I think it is better to copy than to fork.

Run the project using docker

git clone https://github.com/pietheinstrengholt/laravel-docker-k8s

Now run the following command from your terminal one by one. Running the commands be sure that you have installed docker. You will get install instructions from this link

docker-compose build
docker-compose up -d

Now browse project

http://localhost:8181/

Deploy the project using Kubernetes

At first build image running the command:

docker build . -f ./deploy/dockerfile -t laravel-on-k8s:v1

Now login in docker hub. Running the command be sure that you have created an account in docker hub. If not go to the link and create account.

docker login

Now run the following command for Pushing image in docker registry.In the command pietheinstrengholt is my docker id and laravel-on-k8s is repository name and v1 is tag name. Modify command according to your docker id, repository name and tag name.

docker tag laravel-on-k8s:v1 docker.io/pietheinstrengholt/laravel-on-k8s:v1
docker push docker.io/pietheinstrengholt/laravel-on-k8s:v1

Now run minikube. Running the commands be sure that you have installed minikube. If not installed, you can get install instructions from this link

minikube start

If you want to run this using your own image, change the following file: deploy/app/deploy.yml image: docker.io/pietheinstrengholt/laravel-docker-k8s:v1

Now run the following commands for deploying your project:

kubectl apply -f deploy/app/secret.yml
kubectl apply -f deploy/app/deploy.yml
kubectl apply -f deploy/app/service.yml

Now run the following commands to see minikube dashboard:

minikube dashboard

You will get this url :

http://192.168.99.100:30000/#!/overview?namespace=default
kubectl get svc

Running above command you will get following information:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1 443/TCP 27d
laravel-api LoadBalancer 10.0.0.11 80:32676/TCP 4m

Now you can browse your project using following url :

http://192.168.99.100:32676/

TODO

Run the images straight from the docker.io hub:

kubectl run --image=docker.io/pietheinstrengholt/laravel-docker-k8s:v1 laravel-docker-k8s --port=8181 --env="DOMAIN=cluster"
kubectl expose deployment laravel-docker-k8s --port=8181 --name=laravel-docker-k8s

Extra Note :

  • If you want to use different database or different port etc, You have to change in the docker-compose.yml file.
  • If you modify .env file, You have to run following command:
base64 -b -i deploy/env/.env
  • Running the command you will get base 64 encoded string. Put the string in deploy\app\secret.yml. And then run the commands for deploying.