From 6b3071835ddee82882ee19d2fe6daebd1e060cab Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Tue, 20 Sep 2022 21:20:52 +0800 Subject: [PATCH] udpate --- Dockerfile_business | 37 ++++++++++++++++++++ chart/templates/server/business.yaml | 52 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 Dockerfile_business create mode 100644 chart/templates/server/business.yaml diff --git a/Dockerfile_business b/Dockerfile_business new file mode 100644 index 0000000..25df88f --- /dev/null +++ b/Dockerfile_business @@ -0,0 +1,37 @@ +# 多重构建,减少镜像大小 +# 构建:使用golang:1.18版本 +FROM golang:1.18.4 as build + +# 容器环境变量添加,会覆盖默认的变量值 +ENV GO111MODULE=on +ENV GOPROXY=https://goproxy.cn,direct +ENV TZ="Asia/Shanghai" +# 设置工作区 +WORKDIR /go/release + +# 把全部文件添加到/go/release目录 +ADD . . + +# 编译:把main.go编译成可执行的二进制文件,命名为zyos +RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -o zyos cmd/business/main.go + +FROM ubuntu:xenial as prod +LABEL maintainer="dengbiao" +ENV TZ="Asia/Shanghai" + +# 时区纠正 +RUN rm -f /etc/localtime \ + && ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone + +# 在build阶段复制可执行的go二进制文件app +COPY --from=build /go/release/zyos ./zyos + +# 启动服务 +# 优化内核参数 +#RUN sysctl -w net.ipv4.tcp_fin_timeout=15 +#RUN sysctl -w net.ipv4.tcp_tw_recycle=1 +#RUN sysctl -w net.ipv4.ip_local_port_range=1024 65535 +#RUN sysctl -p +#CMD ["bash","-c","sysctl -w net.ipv4.tcp_timestamps=1 && sysctl -w net.ipv4.tcp_tw_reuse=1 && sysctl -w net.ipv4.tcp_tw_timeout=10 && sysctl -w net.ipv4.tcp_fin_timeout=10 && sysctl -w net.ipv4.ip_local_port_range='1024 65535' && ./zyos"] +CMD ["./zyos"] \ No newline at end of file diff --git a/chart/templates/server/business.yaml b/chart/templates/server/business.yaml new file mode 100644 index 0000000..548ed43 --- /dev/null +++ b/chart/templates/server/business.yaml @@ -0,0 +1,52 @@ +# deployment 配置 +apiVersion: apps/v1 +kind: Deployment +metadata: + name: business-deployment + namespace: gim + labels: + app: business +spec: + replicas: 1 + selector: + matchLabels: + app: business + template: + metadata: + labels: + app: business + spec: + containers: + - name: business + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-gim-business:202209020-01' + imagePullPolicy: Always + ports: + - containerPort: 8000 + volumeMounts: # 映射文件为宿主机文件 + - mountPath: /log/ + name: log + env: + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + volumes: + - name: log + hostPath: + path: /log/ +--- +# service 配置 +apiVersion: v1 +kind: Service +metadata: + name: business + namespace: gim + labels: + app: business # 只有设置label,才能被服务发现找到 +spec: + selector: + app: business + ports: + - protocol: TCP + port: 8000 + targetPort: 8000