From 3a3e9f85733b1b70ee86e4f4275f2f3aea05f8ae Mon Sep 17 00:00:00 2001 From: dengbiao Date: Sat, 14 Sep 2024 11:23:30 +0800 Subject: [PATCH] update k8s --- k8s/container_prd.yaml | 107 ++++++++++++++++++++++++++++------------- k8s/ingress_prd.yaml | 20 ++++++++ 2 files changed, 94 insertions(+), 33 deletions(-) create mode 100644 k8s/ingress_prd.yaml diff --git a/k8s/container_prd.yaml b/k8s/container_prd.yaml index e2dc9da..682db9f 100644 --- a/k8s/container_prd.yaml +++ b/k8s/container_prd.yaml @@ -1,49 +1,90 @@ -apiVersion: apps/v1 kind: Deployment +apiVersion: apps/v1 +# 元数据 metadata: - namespace: zhios - name: zhios-mall + name: advertisement-agent + namespace: advertisement labels: - app: zhios-mall + app: advertisement-agent + annotations: + kubesphere.io/creator: dengbiao + kubesphere.io/description: advertisement-agent +# deployment主要部分 spec: replicas: 1 + selector: + matchLabels: + # 名称与上面的labels对应 + app: advertisement-agent template: metadata: - name: zhios-mall labels: - app: zhios-mall + # 名称与上面的matchLabels对应 + app: advertisement-agent spec: - containers: - - name: zhios-mall-container - image: registry-vpc.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-mall:0.1 - ports: - - containerPort: 5002 - name: 5002tcp - protocol: TCP - resources: - limits: - cpu: "1" - memory: 256Mi - requests: - cpu: 200m - memory: 128Mi - imagePullPolicy: IfNotPresent - restartPolicy: Always + # 声明挂载卷(将外部已存在的pvc、config等挂载进来) volumes: + # 用于时区校正 - name: host-time hostPath: path: /etc/localtime type: '' - - name: mall-cfg + # 将前面创建的configMap也挂载进来 + - name: advertisement-agent-cfg configMap: - name: zhios-mall-cfg + # 这里的名字就是前面创建的configMap的名字 + name: advertisement-agent-cfg defaultMode: 420 - selector: - matchLabels: - app: zhios-mall - - strategy: - type: RollingUpdate - rollingUpdate: - maxUnavailable: 25% - maxSurge: 25% + # pvc + - name: advertisement-agent-pvc # 在该部署中的名称,后面使用改名称挂载 + persistentVolumeClaim: + claimName: advertisement-agent-pvc # pvc的名称 + # Nginx配置 + - name: advertisement-agent-nginx + configMap: + name: advertisement-agent-nginx # 外部configMap的名称 + items: + - key: go.conf + path: default.conf + containers: + # 主容器 + - name: advertisement-agent-container + # 镜像地址(提前打包好并推送的镜像仓库) + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/advertisement-agent:0.0.1' + ports: + - name: ad-1003 + # 容器端口号(注意与golang web server启动的端口一致) + containerPort: 1003 + protocol: TCP + # 将前面volume声明的需要用到的pvc、config挂载上来 + volumeMounts: + - name: host-time + readOnly: true + mountPath: /etc/localtime + - name: advertisement-agent-cfg # 该名字对应前面volumes声明的名字 + readOnly: true + # 挂载到容器的哪个路径 + mountPath: /var/zyos + imagePullPolicy: Always + # Nginx 容器 + - name: nginx + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/nginx:latest' + ports: + - name: http-80 + containerPort: 80 + protocol: TCP + volumeMounts: + # 时区校正 + - name: host-time + readOnly: true + mountPath: /etc/localtime + # 存储卷 用于存放前端代码 + - name: advertisement-agent-pvc # 前面volumes声明的名称 + mountPath: /usr/share/nginx/html + - name: advertisement-agent-nginx # Nginx 配置 + readOnly: true + mountPath: /etc/nginx/conf.d/default.conf + subPath: default.conf + restartPolicy: Always + terminationGracePeriodSeconds: 30 + dnsPolicy: ClusterFirst \ No newline at end of file diff --git a/k8s/ingress_prd.yaml b/k8s/ingress_prd.yaml new file mode 100644 index 0000000..65e5278 --- /dev/null +++ b/k8s/ingress_prd.yaml @@ -0,0 +1,20 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod + kubesphere.io/creator: dengbiao + name: advertisement-agent + namespace: advertisement +spec: + rules: + - host: '*.addl.zhiyingos.cn' + http: + paths: + - backend: + service: + name: advertisement-agent + port: + number: 80 + path: / + pathType: ImplementationSpecific