You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# PHP - Examples: PHP-FPM & NGINX & MySQL (using DHI) for K8s/Kubernetes
2
+
3
+
## Steps:
4
+
1.```kubectl apply -f namespace.yaml```
5
+
2. Registry Login (needed for DHI), see below.
6
+
2.```kubectl apply -f volumes.yaml```
7
+
3.```kubectl apply -f wsc-db.yaml```
8
+
* create database and user and set permission:
9
+
```sh
10
+
# Database
11
+
kubectl -n wsc exec -it deployment/wsc-db -c mysql -- sh -c 'mysql -uroot -e "CREATE DATABASE ${MYSQL_DATABASE};"'
12
+
# User with Password and Permission for Database
13
+
kubectl -n wsc exec -it deployment/wsc-db -c mysql -- sh -c 'mysql -uroot -e "CREATE USER \"${MYSQL_USER}\"@\"%\" IDENTIFIED BY \"${MYSQL_PASSWORD}\"; GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO \"${MYSQL_USER}\"@\"%\";"'
14
+
```
15
+
* create exporter user with password and set permission:
16
+
```sh
17
+
kubectl -n wsc exec -it deployment/wsc-db -c mysql -- sh -c 'mysql -uroot -e "CREATE USER \"${MYSQL_EXPORTER_USER}\"@\"%\" IDENTIFIED BY \"${MYSQL_EXPORTER_PASSWORD}\"; GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO \"${MYSQL_EXPORTER_USER}\"@\"%\";"'
18
+
```
19
+
* check:
20
+
```sh
21
+
kubectl -n wsc exec -it deployment/wsc-db -c mysql -- sh -c 'mysql -h localhost -uroot -e "SELECT user, host, max_user_connections FROM mysql.user;"'
22
+
kubectl -n wsc exec -it deployment/wsc-db -c mysql -- sh -c 'mysql -h localhost -uroot -e "SELECT host, user, db FROM mysql.db;"'
23
+
```
24
+
* Now you can edit `wsc-db.yaml` and use `MYSQL_EXPORTER_USER` and `MYSQLD_EXPORTER_PASSWORD`for exporter and optional use other user instead root for healtcheck.
25
+
4. ```kubectl apply -f wsc-web.yaml```
26
+
5. copy wsc files to html folder in wsc-web deployment: ```kubectl cp ....```
# TODO: only do this commands after first start when using dhi mysql image (create database and user with password from environment vars):
10
+
# kubectl -n wsc exec -it deployment/wsc-db -c mysql -- sh -c 'mysql -uroot -e "CREATE DATABASE ${MYSQL_DATABASE};"'
11
+
# kubectl -n wsc exec -it deployment/wsc-db -c mysql -- sh -c 'mysql -uroot -e "CREATE USER \"${MYSQL_USER}\"@\"%\" IDENTIFIED BY \"${MYSQL_PASSWORD}\"; GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO \"${MYSQL_USER}\"@\"%\";"'
12
+
# kubectl -n wsc exec -it deployment/wsc-db -c mysql -- sh -c 'mysql -uroot -e "CREATE USER \"${MYSQL_EXPORTER_USER}\"@\"%\" IDENTIFIED BY \"${MYSQL_EXPORTER_PASSWORD}\"; GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO \"${MYSQL_EXPORTER_USER}\"@\"%\";"'
13
+
14
+
---
15
+
16
+
apiVersion: v1
17
+
kind: ConfigMap
18
+
metadata:
19
+
name: wsc-db-env-config
20
+
namespace: wsc
21
+
labels:
22
+
app.kubernetes.io/name: wsc-db
23
+
app.kubernetes.io/component: database
24
+
app.kubernetes.io/part-of: wsc
25
+
data:
26
+
MYSQL_OPTIONS: "--innodb-buffer-pool-size=512M"# only support in DHI (instead of own *.cnf file)
27
+
# the following variables require manual intervention in order to be used (kubectl exec command):
28
+
MYSQL_DATABASE: "woltlab_suite"
29
+
MYSQL_USER: "woltlab_suite"
30
+
MYSQL_EXPORTER_USER: "exporter"
31
+
32
+
---
33
+
34
+
apiVersion: v1
35
+
kind: Secret
36
+
metadata:
37
+
name: wsc-db-env-secret
38
+
namespace: wsc
39
+
labels:
40
+
app.kubernetes.io/name: wsc-db
41
+
app.kubernetes.io/component: database
42
+
app.kubernetes.io/part-of: wsc
43
+
stringData:
44
+
MYSQL_ROOT_PASSWORD: "my-secret-pw"# required !
45
+
# the following variables require manual intervention in order to be used (kubectl exec command):
# docker exec -it wsc-db bash -c 'mysql -uroot -e "CREATE USER \"${MYSQL_USER}\"@\"%\" IDENTIFIED BY \"${MYSQL_PASSWORD}\"; GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO \"${MYSQL_USER}\"@\"%\";"'
0 commit comments