A simple template for starting a PHP 7 application served by NGINX, using Kubernetes (K8S) deployment object. This also works with Minikube, to aid in learning how to use K8S on a local machine.
-
Start Minikube:
$ minikube start Starting local Kubernetes cluster... Kubectl is now configured to use the cluster.
Optional: Use xhyve driver for Docker instead of Virtualbox.
-
Follow Minikube documentation on installing the xhyve driver.
-
Pass the
--vm-driver
argument to "Start Minikube".minikube start --vm-driver=xhyve
-
-
Create a K8S service:
$ kubectl create -f resources/kubernetes/services/local-service.yaml service "local-service" created
-
Create a K8S deployment:
$ kubectl create -f resources/kubernetes/deployments/local-deployment.yaml deployment "local-deployment" created
Optional: Mount local work into the container.
-
Add the a volume info to
resources/kubernetes/deployments/local-deployment.yaml
:image: rabellamy/php7:0.1.0 ports: - containerPort: 9000 + volumeMounts: + - mountPath: /var/www/html + name: src + volumes: + - name: src + hostPath: + path: /PATH/TO/NGINX-PHP-7-K8S-Deployment/src
-
-
Get the URL for the NGINX service that will serve your PHP 7 app:
$ minikube service nginx-service --url
Note, you may see this message until the pods are ready:
Waiting, endpoint for service is not ready yet...
-
$ minikube delete Deleting local Kubernetes cluster... Machine deleted.
We wanted an example of an NGINX and PHP 7 template using the Kubernetes deployment object, and straight K8S configs, but to our knowledge none previously existed. Here you go!
For a templatized solution, consider Helm Charts.