-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.md.template
220 lines (196 loc) · 10.4 KB
/
README.md.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# k8s-openresty-php
> A set of relatively clean but full-featured, split solution to running openresty and php-fpm together but in seperate containers, supporting PHP versions 5.6, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2 maintained by [Parallax](https://parall.ax/)
## Docker Tags
|openresty | Docker tag |
| ------------- | ------------- |
| 1.15.8.2 | prlx/k8s-openresty-php-openresty:release-latest |
| PHP | Docker Tag |
| ------------- | ------------- |
| 5.6 | prlx/k8s-openresty-php-php:release-php-5.6-latest |
| 7.1 | prlx/k8s-openresty-php-php:release-php-7.1-latest |
| 7.2 | prlx/k8s-openresty-php-php:release-php-7.2-latest |
| 7.3 | prlx/k8s-openresty-php-php:release-php-7.3-latest |
| 7.4 | prlx/k8s-openresty-php-php:release-php-7.4-latest |
| 8.0 | prlx/k8s-openresty-php-php:release-php-8.0-latest |
| 8.1 | prlx/k8s-openresty-php-php:release-php-8.1-latest |
| 8.2 | prlx/k8s-openresty-php-php:release-php-8.2-latest |
## Browse all tags on Docker Hub
[Openresty](https://hub.docker.com/r/prlx/k8s-openresty-php-openresty)
[PHP](https://hub.docker.com/r/prlx/k8s-openresty-php-php)
# Environment Variables
These containers work with certain environment variables to control their operation. Environment variables marked as required may be omitted and things may seem to work OK but we do not test against omitting these so you may see some pretty interesting behaviour as a result.
Web/Worker just means whether these have any effect - nothing bad will happen if they are set on both.
For help running these locally with docker run see the [docker run reference](https://docs.docker.com/engine/reference/run/#env-environment-variables)
| Key | Description | Required | Web | Worker |
| --- | --- | --- | --- | --- |
| SITE_NAME | The name of your project, i.e. 'mywebsite'. Used by NR for app name. | ✓ | ✓ | ✓ |
| SITE_BRANCH | The running branch of your project, i.e. 'master'. Used by NR for app name. | ✓ | ✓ | ✓ |
| ENVIRONMENT | The environment you're running in, i.e. 'qa' or 'production'. Used by NR for app name. | ✓ | ✓ | ✓ |
| ATATUS_APM_LICENSE_KEY | Your Atatus license key. Atatus won't be used if this is not set. | ✖ | ✓ | ✓ |
| ATATUS_FRAMEWORK | Manually set the Atatus framework (see Atatus docs, typically "Laravel" or "Symfony") | ✖ | ✓ | ✓ |
| ATATUS_APM_RAW_SQL | Set to any value (1, true, etc) to use raw sql logging into Atatus | ✖ | ✓ | ✓ |
| PHP_MEMORY_MAX | Maximum PHP request memory, in megabytes (i.e. '256'). Defaults to 128. | ✖ | ✓ | ✓ |
| MAX_EXECUTION_TIME | Maximum PHP and Nginx execution/fastcgi read timeout | ✖ | ✓ | ✓ |
| PHP_FPM_WORKERS | Maximum PHP-FPM workers. Defaults to 4 if not set. | ✖ | ✓ | ✖ |
| PHP_FPM_USER | User which PHP-FPM workers are started as. Defaults to nobody. | ✖ | ✓ | ✖ |
| PHP_FPM_GROUP | Group which PHP-FPM workers are started as. Defaults to nobody. | ✖ | ✓ | ✖ |
| DISABLE_OPCACHE | Set to any value (1, true, etc) to disable PHP Opcache | ✖ | ✓ | ✓ |
| PHP_OPCACHE_MEMORY | Maximum PHP request memory, in megabytes (i.e. '64'). Defaults to 16. | ✖ | ✓ | ✓ |
| PHP_OPCACHE_INTERNED_STRING_BUFFER | Maximum PHP interned string buffer memory, in megabytes (i.e. '16'). Defaults to 2. | ✖ | ✓ | ✓ |
| PHP_SESSION_STORE | If not set, PHP uses /tmp for sessions. If set to 'redis', uses redis for sessions | ✖ | ✓ | ✓ |
| PHP_SESSION_STORE_REDIS_HOST | If not set, defaults to 'redis'. Only used if PHP_SESSION_STORE is set to redis | ✖ | ✓ | ✓ |
| PHP_SESSION_STORE_REDIS_PORT | If not set, defaults to 6379. Only used if PHP_SESSION_STORE is set to redis | ✖ | ✓ | ✓ |
| PHP_DISABLE_CACHE_HEADERS | Set to any value (1, true, etc) to disable PHP's default pragma: no-cache headers | ✖ | ✓ | ✖ |
| PHP_ENABLE_SHORT_TAGS | Set to any value (1, true, etc) to enable PHP short tagging | ✖ | ✓ | ✓ |
# The web mode/command
The web mode is what you use to run a web server - unless you're using workers this is the only one you'll be using. It runs all the things you need to be able to run a PHP-FPM container in Kubernetes.
It is also the default behaviour for the docker containers meaning you don't need to specify a command or working directory to run.
## Ports and Services
| Service | Description | Port/Socket |
| ------------- | ------------- | ------------- |
| [Openresty](https://openresty.org/) | Web server | 0.0.0.0:80 |
| [PHP-FPM](https://php-fpm.org/) | PHP running as a pool of workers | 127.0.0.1:9000 |
## K8s Example
### deployment.yaml
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: "true"
labels:
app: 'k8s-openresty-php-74-test'
name: 'k8s-openresty-php-74-test'
namespace: k8s-openresty-php
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 1
selector:
matchLabels:
app: 'k8s-openresty-php-74-test'
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: "true"
labels:
app: 'k8s-openresty-php-74-test'
spec:
volumes:
- name: shared-files
emptyDir: {}
- name: uploads
emptyDir: {}
containers:
- name: php
image: '{{ PHP7.4IMAGEHERE }}'
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 1
exec:
command:
- /healthcheck.sh
- --listen-queue=10 # fails if there are more than 10 processes waiting in the fpm queue
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
readinessProbe:
failureThreshold: 1
exec:
command:
- /healthcheck.sh
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
resources:
limits:
cpu: "1"
memory: 512Mi
requests:
cpu: 50m
memory: 64Mi
volumeMounts:
- name: shared-files
mountPath: /src-shared
- name: uploads
mountPath: /var/nginx-uploads
- name: openresty
image: '{{ OPENRESTYIMAGEHERE }}'
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: openresty
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
readinessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: openresty
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 5
successThreshold: 2
timeoutSeconds: 2
ports:
- containerPort: 80
name: openresty
protocol: TCP
resources:
limits:
cpu: "1"
memory: 512Mi
requests:
cpu: 50m
memory: 64Mi
volumeMounts:
- name: shared-files
mountPath: /src-shared
- name: uploads
mountPath: /var/nginx-uploads
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 20
```
### service.yaml
```yaml
apiVersion: v1
kind: Service
metadata:
name: 'openresty-74-test'
namespace: k8s-openresty-php
spec:
ports:
- name: openresty
port: 80
protocol: TCP
targetPort: 80
selector:
app: 'k8s-openresty-php-74-test'
sessionAffinity: None
type: ClusterIP
```
# Custom Startup Scripts
You can add behaviour to the built-in startup scripts for web, worker or both modes by adding a file to:
| File Path | Runs on |
| --- | --- |
| /start.sh | Web |
| /start-worker.sh | Worker |
| /start-cron.sh | Cron |
# The worker mode/command
The worker will run php artisan queue:work --timeout=$WORKER_TIMEOUT --tries=$WORKER_TRIES.
To run in this mode, change the Docker CMD to be /start-worker.sh instead of the default /start-web.sh.
# PHP Modules
{{ MODULES_TABLE }}