Further README tidy and new kubernetes guide

This commit is contained in:
Ric Harvey
2017-02-14 17:48:58 +00:00
parent 650ccdbe94
commit fc6d46dcec
3 changed files with 156 additions and 30 deletions

View File

@@ -17,52 +17,28 @@ If you have improvements or suggestions please open an issue or pull request on
- [https://github.com/ngineered/nginx-php-fpm](https://github.com/ngineered/nginx-php-fpm)
- [https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/](https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/)
## Running
## Quick Start
To pull from docker hub:
```
docker pull richarvey/nginx-php-fpm:latest
```
### Starting
### Running
To simply run the container:
```
sudo docker run -d richarvey/nginx-php-fpm
```
You can then browse to ```http://<DOCKER_HOST>``` to view the default install files. To find your ```DOCKER_HOST``` use the ```docker inspect``` to get the IP address (normally 172.17.0.2)
To pull code from git when running:
To dynamically pull code from git when starting:
```
docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' richarvey/nginx-php-fpm:latest
```
You can then browse to ```http://<DOCKER_HOST>``` to view the default install files. To find your ```DOCKER_HOST``` use the ```docker inspect``` to get the IP address (normally 172.17.0.2)
For more detailed examples and explanations please refer to the documentation.
## Available Configuration Parameters
The following flags are a list of all the currently supported options that can be changed by passing in the variables to docker with the -e flag.
- **GIT_REPO** : URL to the repository containing your source code. If you are using a personal token, this is the https URL without https://, e.g github.com/project/ for ssh prepend with git@ e.g git@github.com:project.git
- **GIT_BRANCH** : Select a specific branch (optional)
- **GIT_EMAIL** : Set your email for code pushing (required for git to work)
- **GIT_NAME** : Set your name for code pushing (required for git to work)
- **GIT_USE_SSH** : Set this to 1 if you want to use git over SSH (instead of HTTP), useful if you want to use Bitbucket instead of GitHub
- **SSH_KEY** : Private SSH deploy key for your repository base64 encoded (requires write permissions for pushing)
- **GIT_PERSONAL_TOKEN** : Personal access token for your git account (required for HTTPS git access)
- **GIT_USERNAME** : Git username for use with personal tokens. (required for HTTPS git access)
- **WEBROOT** : Change the default webroot directory from `/var/www/html` to your own setting
- **ERRORS** : Set to 1 to display PHP Errors in the browser
- **HIDE_NGINX_HEADERS** : Disable by setting to 0, default behaviour is to hide nginx + php version in headers
- **PHP_MEM_LIMIT** : Set higher PHP memory limit, default is 128 Mb
- **PHP_POST_MAX_SIZE** : Set a larger post_max_size, default is 100 Mb
- **PHP_UPLOAD_MAX_FILESIZE** : Set a larger upload_max_filesize, default is 100 Mb
- **DOMAIN** : Set domain name for Lets Encrypt scripts
- **REAL_IP_HEADER** : set to 1 to enable real ip support in the logs
- **REAL_IP_FROM** : set to your CIDR block for real ip in logs
- **RUN_SCRIPTS** : Set to 1 to execute scripts
- **PGID** : Set to GroupId you want to use for nginx (helps permissions when using local volume)
- **PUID** : Set to UserID you want to use for nginx (helps permissions when using local volume)
## Documentation
- [Building from source](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/building.md)
- [Config Flags](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/config_flags.md)
- [Git Auth](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/git_auth.md)
- [Personal Access token](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/git_auth.md#personal-access-token)
- [SSH Keys](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/git_auth.md#ssh-keys)
@@ -81,3 +57,6 @@ The following flags are a list of all the currently supported options that can b
- [Renewal](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/lets_encrypt.md#renewal)
- [PHP Modules](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/php_modules.md)
- [Logging and Errors](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/logs.md)
## Guides
- [Running in Kubernetes](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/guides/kubernetes.md)

24
docs/config_flags.md Normal file
View File

@@ -0,0 +1,24 @@
## Available Configuration Parameters
The following flags are a list of all the currently supported options that can be changed by passing in the variables to docker with the -e flag.
- **GIT_REPO** : URL to the repository containing your source code. If you are using a personal token, this is the https URL without https://, e.g github.com/project/ for ssh prepend with git@ e.g git@github.com:project.git
- **GIT_BRANCH** : Select a specific branch (optional)
- **GIT_EMAIL** : Set your email for code pushing (required for git to work)
- **GIT_NAME** : Set your name for code pushing (required for git to work)
- **GIT_USE_SSH** : Set this to 1 if you want to use git over SSH (instead of HTTP), useful if you want to use Bitbucket instead of GitHub
- **SSH_KEY** : Private SSH deploy key for your repository base64 encoded (requires write permissions for pushing)
- **GIT_PERSONAL_TOKEN** : Personal access token for your git account (required for HTTPS git access)
- **GIT_USERNAME** : Git username for use with personal tokens. (required for HTTPS git access)
- **WEBROOT** : Change the default webroot directory from `/var/www/html` to your own setting
- **ERRORS** : Set to 1 to display PHP Errors in the browser
- **HIDE_NGINX_HEADERS** : Disable by setting to 0, default behaviour is to hide nginx + php version in headers
- **PHP_MEM_LIMIT** : Set higher PHP memory limit, default is 128 Mb
- **PHP_POST_MAX_SIZE** : Set a larger post_max_size, default is 100 Mb
- **PHP_UPLOAD_MAX_FILESIZE** : Set a larger upload_max_filesize, default is 100 Mb
- **DOMAIN** : Set domain name for Lets Encrypt scripts
- **REAL_IP_HEADER** : set to 1 to enable real ip support in the logs
- **REAL_IP_FROM** : set to your CIDR block for real ip in logs
- **RUN_SCRIPTS** : Set to 1 to execute scripts
- **PGID** : Set to GroupId you want to use for nginx (helps permissions when using local volume)
- **PUID** : Set to UserID you want to use for nginx (helps permissions when using local volume)

123
docs/guides/kubernetes.md Normal file
View File

@@ -0,0 +1,123 @@
## Kubernetes Guide
The container can be configured to run in kubernetes pretty easily and you can take advantage of the ```kubectl exec``` command to run the pull and push scripts to sync up with github when there are changes. the guide assumes you have a working kubernetes setup and kubectl is working.
The configuration below is an example of how to get quickly running.
### Configure the application
In this example we'll deploy an example app to its own namespace for ease of separation. Create the following ```example-namespace.yml``` file:
```
apiVersion: v1
kind: Namespace
metadata:
name: example
```
Now create the namespace in kubernetes:
```kubectl create -f example-namespace.yml```
Create the following ```example-app.yml```, this is the bit that actually creates your container and replication controller which references the docker image and your github credentials.
```
apiVersion: v1
kind: ReplicationController
metadata:
namespace: example
name: example-app
labels:
example-component: example-app
spec:
replicas: 1
selector:
example-component: example-app
template:
metadata:
labels:
example-component: example-app
spec:
containers:
- name: example-app
image: richarvey/nginx-php-fpm:latest
imagePullPolicy: Always
env:
- name: SSH_KEY
value: '<YOUR_KEY_HERE>'
- name: GIT_REPO
value: 'git@gitlab.com:<YOUR_USER>/<YOUR_REPO>.git'
- name: GIT_EMAIL
value: '<YOUR_EMAIL>'
- name: GIT_NAME
value: '<YOUR_NAME>'
ports:
- containerPort: 80
```
Now run:
```kubectl create -f example-app.yml```
### Using the application
Your container should now be up and running and you can see its details with the following commands:
```
kubectl get pods --namespace example
# make a note of the pod namespace
kubectl describe pod <pod_name> --namespace example
```
### Create a Service for the application
To help expose the application to the outside world you may want to create a service. The example below isn't the only way to do this as it depends on the exact setup of the kubernetes system you have, for example you may want to use an ELB on AWS or you may be on GKE and use googles http load balancer.
Create the file ```example-service.yml``` with the following content:
```
apiVersion: v1
kind: Service
metadata:
namespace: example
name: example-app
spec:
type: ClusterIP
ports:
- protocol: TCP
name: http
port: 80
targetPort: 80
selector:
app: example-app
```
Now run:
```
kubectl create -f example-service.yml
```
This will create you a service load balancer and allow you to scale your replication controller in the background underneath a unifying IP address. You can get the details by running:
```
kubectl describe service example-app --namespace example
```
### Running commands in the container/pod
If you want to push or pull code to the container you can run the following commands:
```
kubectl get pods --namespace example
# make a note of the pod namespace
# update code in the container
kubectl exec -t <pod_name> /usr/bin/pull --namespace example
# push code back to github
kubectl exec -t <pod_name> /usr/bin/push --namespace example
```
If you want to drop into the shell run the following:
```
kubectl exec -it <pod_name> bash --namespace example
```
### Scale your app
You can scale the replication controller with the following command:
```
kubectl scale --replicas=3 rc/example-app --namespace example
```