datard 2 years ago
parent
commit
d2f24df595
1 changed files with 113 additions and 14 deletions
  1. 113 14
      deploy-tmp-template.yaml

+ 113 - 14
deploy-tmp-template.yaml

@@ -17,22 +17,57 @@ spec:
       labels:
         app: [APP]
     spec:
-      terminationGracePeriodSeconds: 60
+      readinessGates:
+          - conditionType: InPlaceUpdateReady
+      terminationGracePeriodSeconds: 180
+      dnsPolicy: ClusterFirstWithHostNet
+      dnsConfig:
+        nameservers:
+          - 223.5.5.5
+          - 114.114.114.114
       initContainers:
         - name: init
           image: hub.evbj.easou.com/dev/busybox
           command: [ "chmod","777","-R","/data" ]
-          imagePullPolicy: Always
+          imagePullPolicy: IfNotPresent
           volumeMounts:
             - name: volume
               mountPath: /data
       #nodeSelector:
       #  app.touchrs: touchrs
+      affinity:
+        podAntiAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+          - weight: 100
+            podAffinityTerm:
+              labelSelector:
+                matchExpressions:
+                - key: app
+                  operator: In
+                  values:
+                  - [APP]
+              topologyKey: kubernetes.io/hostname
       containers:
         - name: [APP]
           image: hub.evbj.easou.com/[ENV]/[APP]:[TAG]
-          imagePullPolicy: Always
+          imagePullPolicy: IfNotPresent
           env:
+            - name: MY_NODE_NAME
+              valueFrom:
+                fieldRef:
+                  fieldPath: spec.nodeName
+            - name: MY_POD_IP
+              valueFrom:
+                fieldRef:
+                  fieldPath: status.podIP
+            - name: MY_POD_NAME
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.name
+            - name: MY_POD_NAMESPACE
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.namespace
             - name: JAVA_OPTS
               value: "-server [DEBUG_OPTS] -Xmx2g -Xms2g -Xss512k -Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=[PROFILE]"
           ports:
@@ -43,22 +78,52 @@ spec:
           volumeMounts:
             - name: volume
               mountPath: /data
+          lifecycle:
+            preStop:
+              exec:
+                command: ["/bin/sh","-c","curl -H 'loginName:admin' -H 'password:ea1so2ua3dm4in5' -X POST 127.0.0.1:8080/actuator/shutdown"]
           livenessProbe:
-            tcpSocket:
+            httpGet:
+              path: /actuator/health
               port: 8080
-            initialDelaySeconds: 30
-            periodSeconds: 15
+              httpHeaders:
+                - name: loginName
+                  value: admin
+                - name: password
+                  value: ea1so2ua3dm4in5
+            initialDelaySeconds: 40        #60s后启动第一次探测
+            periodSeconds: 15              # 每隔10s启动一次探测
+            timeoutSeconds: 3              # 超时时间3s
+            successThreshold: 1            # 成功1次即表示容器健康
+            failureThreshold: 5            # 连续5次失败,则判定容器不健康,默认3次
           readinessProbe:
             tcpSocket:
               port: 8080
-            initialDelaySeconds: 30
+            initialDelaySeconds: 40
             periodSeconds: 15
+        - image: hub.evbj.easou.com/pro/filebeat:7.13.3
+          imagePullPolicy: IfNotPresent
+          name: filebeat
+          volumeMounts:
+            - name: volume #日志同时挂载在nginx和filebeat中
+              mountPath: /data
+            - name: filebeat-config
+              mountPath: /usr/share/filebeat/filebeat.yml
+              subPath: filebeat.yml
+      volumes:
+        - name: filebeat-config
+          configMap:
+            name: filebeat-config-[APP]
+            items:
+              - key: filebeat.yml
+                path: filebeat.yml
+
   volumeClaimTemplates:
     - metadata:
         name: volume
       spec:
         accessModes: [ "ReadWriteOnce" ]
-        storageClassName: rbd
+        storageClassName: ceph-block
         resources:
           requests:
             storage: 100Gi
@@ -79,19 +144,53 @@ spec:
   selector:
     app: [APP]
 ---
-apiVersion: extensions/v1beta1
+apiVersion: networking.k8s.io/v1
 kind: Ingress
 metadata:
   name: [APP]-ingress
   namespace: [ENV]
-  annotations:
-    kubernetes.io/ingress.class: nginx
 spec:
   rules:
-    - host: [APP]-[ENV].ieasou.cn
+    - host: [ENV]-[APP].ieasou.cn
       http:
         paths:
           - path: /
+            pathType: Prefix
             backend:
-              serviceName: [APP]-svc
-              servicePort: 80
+              service:
+                name: [APP]-svc
+                port:
+                  number: 8080
+  ingressClassName: nginx
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: filebeat-config-[APP]
+  namespace: [ENV]
+data:
+  filebeat.yml: |
+    filebeat.inputs:
+    - type: log
+      enabled: true
+      #多行合并
+      multiline.pattern: '^\[[0-9]{4}-[0-9]{2}-[0-9]{2}'
+      multiline.negate: true
+      multiline.match: after
+      multiline.timeout: 30
+      fields:
+          log_topic: [APP]
+      fields_under_root: true
+      paths:
+        - "/data/logs/app/*.log"
+        - "/data/logs/*.log"
+    output.kafka:
+      version: 2.0.0
+      enable: true
+      hosts: ["kafka-0.kafka-headless.[ENV].svc.cluster.local:9093", "kafka-1.kafka-headless.[ENV].svc.cluster.local:9093", "kafka-2.kafka-headless.[ENV].svc.cluster.local:9093"]
+      topic: 'offline-process-topic'
+      required_acks: 1
+      partition.round_robin:
+        reachable_only: false
+      compression: gzip
+      max_message_bytes: 1000000