Skip to content

Commit fc6d46d

Browse files
author
Ric Harvey
committed
Further README tidy and new kubernetes guide
1 parent 650ccdb commit fc6d46d

File tree

3 files changed

+156
-30
lines changed

3 files changed

+156
-30
lines changed

README.md

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,28 @@ If you have improvements or suggestions please open an issue or pull request on
1717
- [https://github.com/ngineered/nginx-php-fpm](https://github.com/ngineered/nginx-php-fpm)
1818
- [https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/](https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/)
1919

20-
## Running
20+
## Quick Start
2121
To pull from docker hub:
2222
```
2323
docker pull richarvey/nginx-php-fpm:latest
2424
```
25-
### Starting
25+
### Running
2626
To simply run the container:
2727
```
2828
sudo docker run -d richarvey/nginx-php-fpm
2929
```
30-
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)
31-
32-
To pull code from git when running:
30+
To dynamically pull code from git when starting:
3331
```
3432
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
3533
```
3634

37-
For more detailed examples and explanations please refer to the documentation.
38-
39-
## Available Configuration Parameters
40-
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.
41-
42-
- **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
43-
- **GIT_BRANCH** : Select a specific branch (optional)
44-
- **GIT_EMAIL** : Set your email for code pushing (required for git to work)
45-
- **GIT_NAME** : Set your name for code pushing (required for git to work)
46-
- **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
47-
- **SSH_KEY** : Private SSH deploy key for your repository base64 encoded (requires write permissions for pushing)
48-
- **GIT_PERSONAL_TOKEN** : Personal access token for your git account (required for HTTPS git access)
49-
- **GIT_USERNAME** : Git username for use with personal tokens. (required for HTTPS git access)
50-
- **WEBROOT** : Change the default webroot directory from `/var/www/html` to your own setting
51-
- **ERRORS** : Set to 1 to display PHP Errors in the browser
52-
- **HIDE_NGINX_HEADERS** : Disable by setting to 0, default behaviour is to hide nginx + php version in headers
53-
- **PHP_MEM_LIMIT** : Set higher PHP memory limit, default is 128 Mb
54-
- **PHP_POST_MAX_SIZE** : Set a larger post_max_size, default is 100 Mb
55-
- **PHP_UPLOAD_MAX_FILESIZE** : Set a larger upload_max_filesize, default is 100 Mb
56-
- **DOMAIN** : Set domain name for Lets Encrypt scripts
57-
- **REAL_IP_HEADER** : set to 1 to enable real ip support in the logs
58-
- **REAL_IP_FROM** : set to your CIDR block for real ip in logs
59-
- **RUN_SCRIPTS** : Set to 1 to execute scripts
60-
- **PGID** : Set to GroupId you want to use for nginx (helps permissions when using local volume)
61-
- **PUID** : Set to UserID you want to use for nginx (helps permissions when using local volume)
35+
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)
6236

37+
For more detailed examples and explanations please refer to the documentation.
6338
## Documentation
6439

6540
- [Building from source](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/building.md)
41+
- [Config Flags](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/config_flags.md)
6642
- [Git Auth](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/git_auth.md)
6743
- [Personal Access token](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/git_auth.md#personal-access-token)
6844
- [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
8157
- [Renewal](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/lets_encrypt.md#renewal)
8258
- [PHP Modules](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/php_modules.md)
8359
- [Logging and Errors](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/logs.md)
60+
61+
## Guides
62+
- [Running in Kubernetes](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/guides/kubernetes.md)

docs/config_flags.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Available Configuration Parameters
2+
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.
3+
4+
- **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
5+
- **GIT_BRANCH** : Select a specific branch (optional)
6+
- **GIT_EMAIL** : Set your email for code pushing (required for git to work)
7+
- **GIT_NAME** : Set your name for code pushing (required for git to work)
8+
- **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
9+
- **SSH_KEY** : Private SSH deploy key for your repository base64 encoded (requires write permissions for pushing)
10+
- **GIT_PERSONAL_TOKEN** : Personal access token for your git account (required for HTTPS git access)
11+
- **GIT_USERNAME** : Git username for use with personal tokens. (required for HTTPS git access)
12+
- **WEBROOT** : Change the default webroot directory from `/var/www/html` to your own setting
13+
- **ERRORS** : Set to 1 to display PHP Errors in the browser
14+
- **HIDE_NGINX_HEADERS** : Disable by setting to 0, default behaviour is to hide nginx + php version in headers
15+
- **PHP_MEM_LIMIT** : Set higher PHP memory limit, default is 128 Mb
16+
- **PHP_POST_MAX_SIZE** : Set a larger post_max_size, default is 100 Mb
17+
- **PHP_UPLOAD_MAX_FILESIZE** : Set a larger upload_max_filesize, default is 100 Mb
18+
- **DOMAIN** : Set domain name for Lets Encrypt scripts
19+
- **REAL_IP_HEADER** : set to 1 to enable real ip support in the logs
20+
- **REAL_IP_FROM** : set to your CIDR block for real ip in logs
21+
- **RUN_SCRIPTS** : Set to 1 to execute scripts
22+
- **PGID** : Set to GroupId you want to use for nginx (helps permissions when using local volume)
23+
- **PUID** : Set to UserID you want to use for nginx (helps permissions when using local volume)
24+

docs/guides/kubernetes.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
## Kubernetes Guide
2+
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.
3+
4+
The configuration below is an example of how to get quickly running.
5+
6+
### Configure the application
7+
8+
In this example we'll deploy an example app to its own namespace for ease of separation. Create the following ```example-namespace.yml``` file:
9+
10+
```
11+
apiVersion: v1
12+
kind: Namespace
13+
metadata:
14+
name: example
15+
```
16+
17+
Now create the namespace in kubernetes:
18+
19+
```kubectl create -f example-namespace.yml```
20+
21+
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.
22+
23+
```
24+
apiVersion: v1
25+
kind: ReplicationController
26+
metadata:
27+
namespace: example
28+
name: example-app
29+
labels:
30+
example-component: example-app
31+
spec:
32+
replicas: 1
33+
selector:
34+
example-component: example-app
35+
template:
36+
metadata:
37+
labels:
38+
example-component: example-app
39+
spec:
40+
containers:
41+
- name: example-app
42+
image: richarvey/nginx-php-fpm:latest
43+
imagePullPolicy: Always
44+
env:
45+
- name: SSH_KEY
46+
value: '<YOUR_KEY_HERE>'
47+
- name: GIT_REPO
48+
value: 'git@gitlab.com:<YOUR_USER>/<YOUR_REPO>.git'
49+
- name: GIT_EMAIL
50+
value: '<YOUR_EMAIL>'
51+
- name: GIT_NAME
52+
value: '<YOUR_NAME>'
53+
ports:
54+
- containerPort: 80
55+
```
56+
Now run:
57+
58+
```kubectl create -f example-app.yml```
59+
60+
### Using the application
61+
62+
Your container should now be up and running and you can see its details with the following commands:
63+
64+
```
65+
kubectl get pods --namespace example
66+
67+
# make a note of the pod namespace
68+
69+
kubectl describe pod <pod_name> --namespace example
70+
```
71+
72+
### Create a Service for the application
73+
74+
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.
75+
76+
Create the file ```example-service.yml``` with the following content:
77+
78+
```
79+
apiVersion: v1
80+
kind: Service
81+
metadata:
82+
namespace: example
83+
name: example-app
84+
spec:
85+
type: ClusterIP
86+
ports:
87+
- protocol: TCP
88+
name: http
89+
port: 80
90+
targetPort: 80
91+
selector:
92+
app: example-app
93+
```
94+
Now run:
95+
```
96+
kubectl create -f example-service.yml
97+
```
98+
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:
99+
```
100+
kubectl describe service example-app --namespace example
101+
```
102+
### Running commands in the container/pod
103+
If you want to push or pull code to the container you can run the following commands:
104+
```
105+
kubectl get pods --namespace example
106+
107+
# make a note of the pod namespace
108+
109+
# update code in the container
110+
kubectl exec -t <pod_name> /usr/bin/pull --namespace example
111+
# push code back to github
112+
kubectl exec -t <pod_name> /usr/bin/push --namespace example
113+
```
114+
If you want to drop into the shell run the following:
115+
```
116+
kubectl exec -it <pod_name> bash --namespace example
117+
```
118+
119+
### Scale your app
120+
You can scale the replication controller with the following command:
121+
```
122+
kubectl scale --replicas=3 rc/example-app --namespace example
123+
```

0 commit comments

Comments
 (0)