Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ripeworks/wordpress-cluster
Run a scalable, stateless cluster of Wordpress sites on AWS
https://github.com/ripeworks/wordpress-cluster
aws efs kubernetes lambda wordpress
Last synced: 2 months ago
JSON representation
Run a scalable, stateless cluster of Wordpress sites on AWS
- Host: GitHub
- URL: https://github.com/ripeworks/wordpress-cluster
- Owner: ripeworks
- Created: 2018-03-05T18:28:01.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-28T14:57:25.000Z (12 months ago)
- Last Synced: 2024-04-15T00:21:01.290Z (10 months ago)
- Topics: aws, efs, kubernetes, lambda, wordpress
- Language: PHP
- Homepage:
- Size: 31.3 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wordpress-cluster
Run a scalable, stateless cluster of Wordpress sites on AWS
## Initial Setup
1. Create an EFS
2. `ssh` into a new or existing instance (EC-2, Kubernetes node, etc) and mount the EFS.```
$ sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport {EFS dns name}:/ /mnt/efs
```3. Use SFTP or wp-cli to set up your wordpress websites inside of the EFS.
4. Create a MySQL compatible database and set up your database(s). (RDS, PlanetScale, etc)## Lambda
Use a php runtime layer on AWS Lambda to run Wordpress. Wordpress root is persisted through EFS.
### Structure
![](docs/infra-lambda.svg)
#### Cloudfront
The entry point of any user request will be to a CloudFront distribution. The distribution origin points to the Lambda function URL. The website domain and certificate should CNAME to the distribution.
#### Lambda
The serverless.yml should allow for easy deployment of a lambda function. Once the function is created, use the function's url to set up your CloudFront distribution.
The Lambda function uses a custom layer from the serverless PHP runtime, Bref.
- [Bref Documentation](https://bref.sh/docs)
- [Bref runtimes](https://runtimes.bref.sh/)An EFS access point must be attached to the function, and for this your Lambda function will need to be in a VPC. Which also most likely means you will need a NAT Gateway in your VPC to access the internet.
### Resources
- [KotobaMedia/terraform-aws-wordpress-on-lambda-efs](https://github.com/KotobaMedia/terraform-aws-wordpress-on-lambda-efs)
Pretty much lifted the entire Lambda setup from this repo, thank you!
## Kubernetes
Use Kubernetes as a container platform to run tiny stateless instances of Wordpress. Each container uses EFS for file storage, and RDS for database storage.
### Structure
This setup is intended for running multiple separate Wordpress websites. A lot of setups I see are for setting up a cluster for running only one website.
![](docs/infra-kube.svg)
#### Cloudfront
The entry point of any user request will be to a CloudFront distribution. The distribution should be tied to the main domain name using CNAMEs as well as have a valid SSL cert attached (ACM). For each different Wordpress you have, set up a distribution. All of the distributions will route to the single ELB instance. The traffic to the ELB is done over SSL, so make sure you have a certificate attached to your ELB, and that the cloudfront distributions point to that domain name.
#### LoadBalancer
The Kubernetes cluster has one main LoadBalancer in the form of an ELB. Each request coming into the ELB will be passed to the individual nodes.
#### Proxy
All requests from the ELB are sent into an nginx proxy deployment which will route the request to the appropriate Wordpress deployment usually based on the hostname of the request.
#### Container
Each Wordpress site is served by one or more containers. Each container is a basic Alpine linux image with php7, php-fpm, and nginx. The containers will volume mount to EFS at the specified location where its Wordpress root is.
### Setup
1. Setup your Kubernetes cluster using KOPS
2. Ensure Wordpress sites are in your EFS. This repo uses `/wordpress//` as its structure for each website.```
/
└── wordpress
└── example.com
├── logs
├── sessions
├── wordpress # Wordpress root
└── wp-config.php
```**Note:** Containers will volume mount `/wordpress/mywebsite` from the EFS to `/app`
5. Deploy `proxy-deployment.yml` to set up your nginx proxy and ELB.
6. Set up each deployment using `wordpress-deployment.yml` as a template. Deploy as many for as many sites as you want.