test-project

This commit is contained in:
tusuii
2026-03-09 22:50:46 +05:30
parent 24dbab7cce
commit 86a1f0b15c
20 changed files with 1192 additions and 3 deletions

View File

@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
namespace: react-mysql
spec:
replicas: 1
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
initContainers:
- name: wait-for-mysql
image: busybox:1.36
command: ["sh", "-c", "until nc -z mysql 3306; do echo waiting for mysql; sleep 3; done"]
containers:
- name: backend
image: subkamble/react-mysql-backend:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: app-secret
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
readinessProbe:
httpGet:
path: /user
port: 3000
initialDelaySeconds: 10
periodSeconds: 10
livenessProbe:
httpGet:
path: /user
port: 3000
initialDelaySeconds: 20
periodSeconds: 20

View File

@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: backend
namespace: react-mysql
spec:
selector:
app: backend
ports:
- port: 3000
targetPort: 3000

View File

@@ -0,0 +1,4 @@
DB_HOST=mysql
DB_PORT=3306
DB_USER=root
DB_NAME=appdb

View File

@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
namespace: react-mysql
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: subkamble/react-mysql-frontend:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 200m
memory: 256Mi
readinessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 10
periodSeconds: 10
livenessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 20
periodSeconds: 20

View File

@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: frontend
namespace: react-mysql
spec:
selector:
app: frontend
ports:
- port: 3000
targetPort: 3000

View File

@@ -0,0 +1,25 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: react-mysql
resources:
- namespace.yaml
- mysql/configmap-sql.yaml
- mysql/statefulset.yaml
- mysql/service.yaml
- backend/deployment.yaml
- backend/service.yaml
- frontend/deployment.yaml
- frontend/service.yaml
configMapGenerator:
- name: app-config
envs:
- config.properties
secretGenerator:
- name: app-secret
envs:
- secret.properties
type: Opaque

View File

@@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-init-sql
namespace: react-mysql
data:
script.sql: |
-- Create the appdb database
CREATE DATABASE IF NOT EXISTS appdb;
-- Use the appdb database
USE appdb;
-- Create the apptb table
CREATE TABLE `appdb`.`apptb` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`));

View File

@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: react-mysql
spec:
clusterIP: None
selector:
app: mysql
ports:
- port: 3306
targetPort: 3306

View File

@@ -0,0 +1,66 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
namespace: react-mysql
spec:
serviceName: mysql
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:8.0
ports:
- containerPort: 3306
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: app-secret
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: app-secret
key: MYSQL_ROOT_PASSWORD
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
- name: mysql-init
mountPath: /docker-entrypoint-initdb.d
resources:
requests:
cpu: 250m
memory: 512Mi
limits:
cpu: 500m
memory: 1Gi
readinessProbe:
exec:
command: ["mysqladmin", "ping", "-h", "localhost"]
initialDelaySeconds: 20
periodSeconds: 10
livenessProbe:
exec:
command: ["mysqladmin", "ping", "-h", "localhost"]
initialDelaySeconds: 40
periodSeconds: 20
volumes:
- name: mysql-init
configMap:
name: mysql-init-sql
volumeClaimTemplates:
- metadata:
name: mysql-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 2Gi

4
k8s/base/namespace.yaml Normal file
View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: react-mysql