Update PHP test app - 2026-01-21 13:37:13
This commit is contained in:
25
php-test/k8s/ingress.yaml
Normal file
25
php-test/k8s/ingress.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: php-app
|
||||
namespace: php-test
|
||||
annotations:
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
tls:
|
||||
- hosts:
|
||||
- php.u9.net3w.com
|
||||
secretName: php-app-tls
|
||||
rules:
|
||||
- host: php.u9.net3w.com
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: php-app
|
||||
port:
|
||||
number: 80
|
||||
16
php-test/k8s/mysql-configmap.yaml
Normal file
16
php-test/k8s/mysql-configmap.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: mysql-init-sql
|
||||
namespace: php-test
|
||||
data:
|
||||
init.sql: |
|
||||
USE test_db;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS test_data (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
email VARCHAR(100) NOT NULL,
|
||||
message TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
96
php-test/k8s/mysql-deployment.yaml
Normal file
96
php-test/k8s/mysql-deployment.yaml
Normal file
@@ -0,0 +1,96 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: php-test
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: mysql-secret
|
||||
namespace: php-test
|
||||
type: Opaque
|
||||
stringData:
|
||||
MYSQL_ROOT_PASSWORD: "rootpassword"
|
||||
MYSQL_DATABASE: "test_db"
|
||||
MYSQL_USER: "phpuser"
|
||||
MYSQL_PASSWORD: "phppassword"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mysql-pvc
|
||||
namespace: php-test
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mysql
|
||||
namespace: php-test
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mysql
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mysql
|
||||
spec:
|
||||
containers:
|
||||
- name: mysql
|
||||
image: mysql:8.0
|
||||
ports:
|
||||
- containerPort: 3306
|
||||
name: mysql
|
||||
env:
|
||||
- name: MYSQL_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mysql-secret
|
||||
key: MYSQL_ROOT_PASSWORD
|
||||
- name: MYSQL_DATABASE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mysql-secret
|
||||
key: MYSQL_DATABASE
|
||||
- name: MYSQL_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mysql-secret
|
||||
key: MYSQL_USER
|
||||
- name: MYSQL_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mysql-secret
|
||||
key: MYSQL_PASSWORD
|
||||
volumeMounts:
|
||||
- name: mysql-storage
|
||||
mountPath: /var/lib/mysql
|
||||
- name: init-sql
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
volumes:
|
||||
- name: mysql-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: mysql-pvc
|
||||
- name: init-sql
|
||||
configMap:
|
||||
name: mysql-init-sql
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mysql
|
||||
namespace: php-test
|
||||
spec:
|
||||
selector:
|
||||
app: mysql
|
||||
ports:
|
||||
- port: 3306
|
||||
targetPort: 3306
|
||||
clusterIP: None
|
||||
18
php-test/k8s/php-configmap.yaml
Normal file
18
php-test/k8s/php-configmap.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: php-config
|
||||
namespace: php-test
|
||||
data:
|
||||
config.php: |
|
||||
<?php
|
||||
// 数据库配置
|
||||
define('DB_HOST', 'mysql.php-test.svc.cluster.local');
|
||||
define('DB_NAME', 'test_db');
|
||||
define('DB_USER', 'phpuser');
|
||||
define('DB_PASS', 'phppassword');
|
||||
define('DB_CHARSET', 'utf8mb4');
|
||||
|
||||
// 错误报告设置(开发环境)
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
58
php-test/k8s/php-deployment.yaml
Normal file
58
php-test/k8s/php-deployment.yaml
Normal file
@@ -0,0 +1,58 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: php-app
|
||||
namespace: php-test
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: php-app
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: php-app
|
||||
spec:
|
||||
containers:
|
||||
- name: php-app
|
||||
image: registry.u9.net3w.com/php-test:latest
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 80
|
||||
name: http
|
||||
volumeMounts:
|
||||
- name: php-config
|
||||
mountPath: /var/www/html/config.php
|
||||
subPath: config.php
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
volumes:
|
||||
- name: php-config
|
||||
configMap:
|
||||
name: php-config
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: php-app
|
||||
namespace: php-test
|
||||
spec:
|
||||
type: NodePort
|
||||
selector:
|
||||
app: php-app
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
nodePort: 30080
|
||||
protocol: TCP
|
||||
name: http
|
||||
Reference in New Issue
Block a user