From 9ffd8d3fba74ef390ee3e6dd849e0191a1eae418 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Fri, 11 Aug 2023 14:50:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84k8s=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- k8s/base/kustomization.yaml | 2 + k8s/base/nginx.yaml | 73 +++++++++++++++++++++++++++++++++++ k8s/base/ns.yaml | 4 ++ k8s/master/kustomization.yaml | 46 ++++++++++++++++++++-- k8s/test/kustomization.yaml | 41 ++++++++++---------- 5 files changed, 141 insertions(+), 25 deletions(-) create mode 100644 k8s/base/nginx.yaml create mode 100644 k8s/base/ns.yaml diff --git a/k8s/base/kustomization.yaml b/k8s/base/kustomization.yaml index 789822a3..4a8a7fe1 100644 --- a/k8s/base/kustomization.yaml +++ b/k8s/base/kustomization.yaml @@ -2,6 +2,8 @@ resources: - api.yaml - redis.yaml - pg.yaml + - ns.yaml + - nginx.yaml diff --git a/k8s/base/nginx.yaml b/k8s/base/nginx.yaml new file mode 100644 index 00000000..8649431b --- /dev/null +++ b/k8s/base/nginx.yaml @@ -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 \ No newline at end of file diff --git a/k8s/base/ns.yaml b/k8s/base/ns.yaml new file mode 100644 index 00000000..d428c7a0 --- /dev/null +++ b/k8s/base/ns.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: coal \ No newline at end of file diff --git a/k8s/master/kustomization.yaml b/k8s/master/kustomization.yaml index 4525c0da..47ce33bd 100644 --- a/k8s/master/kustomization.yaml +++ b/k8s/master/kustomization.yaml @@ -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" diff --git a/k8s/test/kustomization.yaml b/k8s/test/kustomization.yaml index fe2faf70..88d956bc 100644 --- a/k8s/test/kustomization.yaml +++ b/k8s/test/kustomization.yaml @@ -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"