完善k8s文件

This commit is contained in:
2023-08-11 14:50:14 +08:00
parent b234a8c849
commit 9ffd8d3fba
5 changed files with 141 additions and 25 deletions

View File

@@ -2,6 +2,8 @@ resources:
- api.yaml
- redis.yaml
- pg.yaml
- ns.yaml
- nginx.yaml

73
k8s/base/nginx.yaml Normal file
View File

@@ -0,0 +1,73 @@
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: NodePort
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
default.conf: |
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
proxypass http://coal-ui:7456/;
}
location /api {
proxypass http://coal-api:7456/;
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /etc/nginx/conf.d/default.conf
name: nginx-conf
subPath: default.conf
restartPolicy: Always
volumes:
- name: nginx-conf
configMap:
items:
- key: default.conf
path: default.conf

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

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

View File

@@ -1,7 +1,7 @@
resources:
- ../base
namespace: coal
namespace: coal-master
images:
- name: redis
@@ -14,10 +14,48 @@ images:
commonLabels:
branch: master
nameSuffix: -master
patchesStrategicMerge:
- |
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: NodePort
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
default.conf: |
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
proxypass http://coal-ui.coal-master.svc.cluster.local:80/;
}
location /api {
proxypass http://coal-api.coal-master.svc.cluster.local:7456/;
}
}
- |
apiVersion: apps/v1
kind: Deployment
@@ -30,8 +68,8 @@ patchesStrategicMerge:
- name: coal-api
env:
- name: PG_HOST
value: "pg-master.coal.svc.cluster.local"
value: "pg.coal-master.svc.cluster.local"
- name: REDIS_HOST
value: "redis-master.coal.svc.cluster.local"
value: "redis.coal-master.coal.svc.cluster.local"
- name: SPRING_PROFILES_ACTIVE
value: "master"

View File

@@ -1,7 +1,7 @@
resources:
- ../base
namespace: coal
namespace: coal-test
images:
- name: redis
@@ -14,25 +14,24 @@ images:
commonLabels:
branch: test
nameSuffix: -test
replacements:
- source:
kind: Service
name: pg-test
targets:
- select:
kind: Deployment
name: coal-api
fieldPaths:
- spec.template.spec.containers.[name=coal-api].env.[name=PG_HOST].value
- source:
kind: Service
name: redis-test
targets:
- select:
kind: Deployment
name: coal-api
fieldPaths:
- spec.template.spec.containers.[name=coal-api].env.[name=REDIS_HOST].value
patchesStrategicMerge:
- |
apiVersion: apps/v1
kind: Deployment
metadata:
name: coal-api
spec:
template:
spec:
containers:
- name: coal-api
env:
- name: PG_HOST
value: "pg.coal-test.svc.cluster.local"
- name: REDIS_HOST
value: "redis.coal-test.coal.svc.cluster.local"
- name: SPRING_PROFILES_ACTIVE
value: "test"