Overview of Deploying Applications on Containers
Running Containers at any real-world scale requires container orchestration, and scheduling platform like Docker Swarm, Apache Mesos, AWS ECS but the most popular out of it is Kubernetes. Kubernetes is an open source system for automating deployment and management of containerized applications.
In this post, We’ll share the process how you can Develop and Deploy Microservices based PHP Laravel Application on the Container Environment – Docker and Kubernetes and adopt DevOps in existing PHP Applications.
Prerequisites For Deploying Laravel Application on Kubernetes
To follow this guide you need –
PHP Laravel Application Source Code
It is an open source platform that automates container operations, and Minikube is best for testing Kubernetes.
Setting Up Kubectl
Kubectl is command line interface to manage Kubernetes cluster either remotely or locally. To configure kubectl on your machine follow this link.
Shared Persistent Storage
Shared Persistent Storage is permanent storage that we can attach to the Kubernetes container so that we don`t lose our data even when container dies. We will be using GlusterFS as the persistent data store for Kubernetes container applications.
PHP Application Source Code
Application Source Code is source code that we want to run inside a Kubernetes container.
Dockerfile contains a bunch of commands to build PHP Laravel application.
The Registry is an online image store for container images.
Below mentioned options are few most popular registries.
Private Docker Hub
Google Container Registry
Writing a Dockerfile
The below-mentioned code is sample Dockerfile for PHP Laravel applications. In which we are using Apache Maven 3 as the builder for PHP Laravel applications and OpenJDK 8 as a base development environment. Alpine Linux is used due to its very compact size.
Below mentioned is the sample Apache2 config file for Laravel application.
Create a file name laravel.conf and add the below-mentioned code to it.
Building PHP Laravel Application Image
The below-mentioned command will build your application container image.
Publishing PHP Laravel Application Container Image
Now we publish our PHP Laravel application container image to any container registry like Docker Hub, AWS ECR, Google Container Registry, Private Docker Registry.
Today I will be using Azure container registry for publishing container images.
You also need to Sign UP to Azure Cloud Platform then create container registry by using the link.
Now use this link to Pull and Push to Azure Container registry.
Similarly, we can push or pull any container image to any of the below-mentioned container registries like Docker Hub, AWS ECR, Google Container Registry, Private Docker Registry etc.
Creating Deployment Files for Kubernetes
Deploying application on Kubernetes with ease using deployment and service files either in JSON or YAML format.
Following Content is for “<name of application>.deployment.yml” file of python container application.
Following Content is for “<name of application>.service.yml” file of python container application.
Running PHP Laravel Application on Kubernetes
PHP Laravel Application Container can be deployed either by Kubernetes Dashboard or Kubectl (Command line).
I`m explaining command line that you can use in production Kubernetes cluster.
Now we have successfully deployed PHP Laravel Application on Kubernetes.
Verifying Application Deployment
We can verify application deployment either by using Kubectl or Kubernetes Dashboard.
Below mentioned command will show you running pods of your application with status running/terminated/stop/created.
Result of above command
Testing Application Deployment
Get the External Node Port using the below-mentioned command. External Node Port is in the range from 30000 to 65000.
Launch web Browser and open any of the below-mentioned URLs.
http://<kubernetes master ip address >: <application service port number>
http://<cluster ip address >: <application port number>
Your PHP Laravel application should be the stateless application before you do application scaling in kubernetes.
You can scale out an application in so many ways. Here I have mentioned two of them which are mostly used.
kubectl scale –current-replicas=1 –replicas=3 deployment/<name of your application>
Using Kubernetes Dashboard
Update your deployment from kubernetes dashboard
Check Status of Pods.
Check Logs of Pods/Containers.
Check Service Port Status.
Check requirements/dependencies of application.
How Can XenonStack Help You
Our DevOps Consulting Services provides DevOps Assessment and Audit of your existing Infrastructure, Development Environment and Integration.
Our DevOps Professional Services includes –
Enable Secure Continuous Integration and Continuous Delivery Pipeline with Jenkins/Bamboo/TeamCity for delivery, automation, self-service environment, and On-demand. Deploy PHP Laravel Application to production by decreasing the time by the automation of entire delivery pipeline comprising build, deploy, test, and release.
Continuous Deployment Cloud Hosting
XenonStack Continuous Deployment Cloud Hosting Services lets you clone your production to staging cluster in less than a minute. Develop, Deploy and Manage your PHP Laravel Application on leading Cloud Service Providers – AWS, Microsoft Azure, Google Cloud, and Container Environment – Kubernetes and Docker.
Take a cloud-native approach to building Enterprise Applications for Web and Mobile with a Microservices Architecture. Run each service inside a container and combine all those containers to form a complex Microservices Application.