Outline: How To Install Development Setup
Outline: How To Install Development Setup
- Why
- - Install minikube
- - Install kubectl
- - Nginx container
- Into Production
- Optional Services
- - Mysql
- - Redis
- - Horizon
- - Cron worker
- Going Live
- SSL
- Deployment strategies
1 of 22
ff
Getting Started
We’ll start out by learning how to run a miniature cluster on our own
computer. Then we’ll move to a production setup using a cloud provider.
First you’ll need to install docker for working with containers. Docker
includes a container runtime and tools to build containers. Head over to
https://www.docker.com and install the latest stable version.
And nally install kubectl. Kubectl is a command line tool that allows you
to interact with a Kubernetes cluster. You’ll use it in production and
development. A cluster and the authentication details needed to access it
are collectively known as a context.
After installing kubectl, try running ‘kubectl con g get-contexts’. You should
see your minikube cluster.
The nginx.conf has a basic con guration to serve the index.html le and
the index.html is the content that will be displayed.
2 of 22
fi
fi
fi
fi
fi
fi
fi
cd into the directory and run the command ‘docker build . --tag=basic-nginx’.
Next run ‘docker run -p 8787:80 basic-nginx’ to start the container. Direct your
browser to http://localhost:8787 to see the output of index.html.
We’ve successfully built and run a container in docker, next we’ll run it on
Kubernetes.
The important parts are the image name which needs to match the tag we
gave in docker build, the imagePullPolicy, and the selector’s matchLabels
which will be used for networking later.
ImagePullPolicy ‘Never’ tells Kubernetes that the image exists locally, i.e.
not on docker hub.
3 of 22
.
fi
—
Everything is red, this doesn’t look good. Click one of the small red dots to
reveal the message about what went wrong.
Failed to pull image "nginx-basic": rpc error: code = Unknown desc = Error
response from daemon: pull access denied for nginx-basic, repository
does not exist or may require 'docker login': denied: requested access to
the resource is denied
4 of 22
Now we can build our image with ‘docker build . --tag=basic-nginx’. Since
we’ve switched docker environments, now it’ll be available to Kubernetes.
Delete the old deployment then run the same deploy command again. We
should have all green lights in the Kubernetes dashboard now.
Service
—— insert nginx_service.yaml —
In this example, the port routes tra c internally to the same port it
exposes externally. Di erent routing con gurations are possible but this is
all we’ll need.
Ingress
An ingress is how tra c gets from the outside world into the Kubernetes
cluster.
5 of 22
ffi
ff
—
ffi
fi
Now we can create the ingress resource.
—— insert ingress.yaml —
Now we have to wait until our ingress is ready with an endpoint ip address.
It can take a couple of minutes. Run ‘kubectl get ingress’ and when an
address is shown, navigate to that ip to view the output from the container.
It can take over a minute for the address to be lled. If it doesn’t come up,
something else is wrong. Join the discord group and let’s gure it out!
You can delete deployment we created here. We’ll be creating a new one
that can handle php. The service and ingress can be reused.
Running Laravel
We’ve used Nginx to serve a static asset, now let’s use it to serve a php-
fpm container.
Starting from the ground up, rst we’ll create the php-fpm container then
we’ll con gure Nginx to serve static assets and direct php requests to the
php-fpm container.
Building Laravel
First create a new Laravel application and in the root of that directory,
create a le called Docker le.
6 of 22
ff
fi
fi
—
fi
fi
ff
fi
fi
fi
—— Docker le ——
Make sure your docker environment is set to Minikube as before then run
‘docker build . --tag=laravel-php’ from the directory with the new Docker le.
Deploying Laravel
Nginx also needs access to the static assets from our Laravel application.
We’ll create a shared volume that’s accessible to Nginx and php. On
deployment, our Laravel php container will copy the static assets to the
shared volume.
—— basic/laravel/storage.yaml ——
The volume exists in the Minikube virtual machine. You can access it by
running ‘minikube ssh’ then cd to ‘/tmp/hostpath-provisioner/default’.
—— php_deployment.yaml ——
This strategy isn’t perfect because each time a pod is created, it copies
the contents to the shared directory. This can cause unexpected
downtime. Shared volumes are also problematic when using multiple
nodes. We’ll solve that when we get into the production environment.
7 of 22
fi
fi
Accessing Laravel
If you tried to access through the ingress’s endpoint, you will receive a 503
error. We still can’t access our application because php-fpm doesn’t know
how to handle HTTP requests. For that we need an Nginx reverse proxy.
—— nginx_con gmap.yaml ——
—— php_service.yaml ——
The last thing we need to do is create the Nginx deployment with the
con guration le and the shared volume.
—— nginx_deployment.yaml ——
Browse to the address given by the ingress and you should see the
Laravel start page. That’s it for a very basic setup. Next we’ll dig into a fully
edged production setup covering Redis, MySQL, Horizon, and Laravel’s
scheduler. We’ll run CI/CD using Github Actions and a zero downtime
deployment script.
8 of 22
fl
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi