Skip to content

Commit

Permalink
Merge pull request #56 from DreamPWJ/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
DreamPWJ authored Feb 21, 2024
2 parents b1f5822 + eb07c61 commit 15358ba
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .ci/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ RUN tar -pxzvf python.tar.gz >/dev/null 2>&1 \
EXPOSE $EXPOSE_PORT

# 根据主文件默认名称 app.py CMD中的"$MY_VAR"变量设置成 docker run -e MY_VAR=value 运行变量 否则无法获取
CMD ["python", "main.py"]
CMD ["python", "$PYTHON_START_FILE"]

# Flask部署 启动命令
#CMD [ "python", "-m" , "flask", "run", "--host=0.0.0.0"]
Expand Down
2 changes: 1 addition & 1 deletion .ci/python/docker-release-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ echo "👨‍💻 启动运行Docker容器 环境: ${env_mode} 映射端口: ${h
docker run -d --restart=always -p ${host_port}:${expose_port} \
-e "PROJECT_NAME=${project_name}" \
-m ${docker_memory} --log-opt ${docker_log_opts} --log-opt max-file=1 ${dynamic_run_args} \
-e "REMOTE_DEBUGGING_PARAM=${remote_debugging_param}" \
-e "REMOTE_DEBUGGING_PARAM=${remote_debugging_param}" -e "PYTHON_START_FILE=${python_start_file}" \
-v /${deploy_folder}/${project_name}/logs:/logs \
--name ${docker_container_name} ${docker_image_name}

Expand Down
35 changes: 28 additions & 7 deletions _k8s/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,61 @@ metadata:
cert-manager.io/cluster-issuer: letsencrypt-prod
acme.cert-manager.io/http01-edit-in-place: "true"

# 开启金丝雀Canary
# 开启金丝雀Canary
nginx.ingress.kubernetes.io/canary: "true"
# Http Header请求头为version
# Http Header请求头为version
nginx.ingress.kubernetes.io/canary-by-header: "version"
# 请求头version=v2.0.0时,请求才会被路由到新版本服务中
# 请求头version=v2.0.0时,请求才会被路由到新版本服务中
nginx.ingress.kubernetes.io/canary-by-header-value: "v2.0.0"
#nginx.ingress.kubernetes.io/canary-by-header-pattern: ""
#nginx.ingress.kubernetes.io/canary-by-cookie: ""
# 在满足上述匹配规则的基础上仅允许百分比的流量会被路由到新版本服务中
# 在满足上述匹配规则的基础上仅允许百分比的流量会被路由到新版本服务中
nginx.ingress.kubernetes.io/canary-weight: "100"

# 开启跨域
# 开启CORS跨域
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-max-age: "64800"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, DELETE, PATCH, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"

# 数据请求超时时间
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"

# 负载均衡算法 如ip_hash
nginx.ingress.kubernetes.io/upstream-hash-by: "$host"
# Session保持配置
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/affinity-mode: "persistent"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
# 后端大文件上传大小

# 后端大文件上传大小 数据传输大小
nginx.ingress.kubernetes.io/client-body-buffer-size: 1024m
nginx.ingress.kubernetes.io/proxy-max-temp-file-size: 2048m
# 数据传输大小
nginx.ingress.kubernetes.io/proxy-body-size: 1024m

# 配置是否同时支持http和https访问应用
nginx.ingress.kubernetes.io/ssl-redirect: "false"

# 采用了 “漏斗” 算法实现限流 保证服务可用性和被攻击 nginx的限流是一个队列模型。限流连接数为 队列长度+队列处理能力
# 每个IP每秒可以访问的次数 默认乘数为5
nginx.ingress.kubernetes.io/limit-rps: "50"
# 为计算限速漏桶算法的 burst size和 limit-rps 的相乘放大系数 burst为队列长度
nginx.ingress.kubernetes.io/limit-burst-multiplier: "10"
# 配合 limit-window 表示每多少秒全局限速多少次(需要依赖 memcached)
nginx.ingress.kubernetes.io/global-rate-limit: "100000"
nginx.ingress.kubernetes.io/global-rate-limit-window: 1s
# 限制发送给后端服务的发送速率为 多少MB/每秒 rate为队列处理能力
#nginx.ingress.kubernetes.io/limit-rate: 10240
# 发送给后端服务的前 多少MB 数据不进行限速
#nginx.ingress.kubernetes.io/limit-rate-after: 102400
# 白名单 客户端IP源范围要从速率限制中排除。该值是逗号分隔的CIDR列表
#nginx.ingress.kubernetes.io/limit-whitelist:
# 限流超出后的响应码
nginx.ingress.kubernetes.io/configuration-snippet: |
limit_req_status 429;
spec:
ingressClassName: k8s-ingress
tls: # TLS安全
Expand Down
20 changes: 18 additions & 2 deletions _k8s/k8s_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
parser.add_argument('--remote_debug_port', type=int, default=None)
parser.add_argument('--is_use_session', type=bool, default=False)
parser.add_argument('--set_yaml_arags', type=str, default=None)
parser.add_argument('--set_python_start_file', type=str, default=None)
parser.add_argument('--is_k8s_health_probe', type=bool, default=False)

args = parser.parse_args()

Expand Down Expand Up @@ -106,15 +108,23 @@
[*nsf_server_yaml]
)

# 动态设置k8s yaml args参数
# Java动态设置k8s yaml args参数
set_yaml_arags = args.set_yaml_arags
if set_yaml_arags is not None:
print(set_yaml_arags)
# 适配Java Spring Boot框架容器动态启动命令
yaml_containers[0]["command"] = ["java"] # 覆盖或补充 ENTRYPOINT
yaml_containers[0]["command"] = ["java"] # 覆盖或补充 ENTRYPOINT 或 CMD
yaml_containers[0]["args"] = ["-jar", "-Xms128m", set_yaml_arags,
"-Djava.security.egd=file:/dev/./urandom", "/server.jar"]

# 设置python语言相关的参数
set_python_start_file = args.set_python_start_file
if set_python_start_file is not None:
print(set_python_start_file)
# 启动命令
yaml_containers[0]["command"] = ["python"] # 覆盖或补充 ENTRYPOINT 或 CMD
yaml_containers[0]["args"] = [set_python_start_file]

# 业务应用是否使用Session处理
if is_use_session:
service_spec = yamlContent[1]['spec']
Expand All @@ -127,6 +137,12 @@
print(default_port)
yaml_containers[0]['ports'].append({'containerPort': default_port})

# 是否禁止执行K8S默认的健康探测
is_k8s_health_probe = args.is_k8s_health_probe
if is_k8s_health_probe:
del yaml_containers[0]["readinessProbe"]
del yaml_containers[0]["livenessProbe"]

# print(yamlContent)

with open(k8s_yaml_file, mode='w', encoding='utf-8') as file:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Author: 潘维吉
# Description: 云原生K8S中使用cert-manager基于 ACME 协议与 Let's Encrypt 自动签发与续签免费的SSL证书

# 创建一个集群级的签发机构 仅需一次
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod-lanneng-open-park-third-party
namespace: cert-manager
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory # ACME 协议的服务端 acme-staging-v02测试证书没有限制
email: 406798106@qq.com # 证书快过期的时候会有邮件提醒
privateKeySecretRef:
name: letsencrypt-prod-key-lanneng-open-park-third-party # 私钥秘密必须与cert-manager服务在同一个命名空间中才能工作 kubectl delete Secret letsencrypt-prod-key --namespace cert-manager
solvers:
- http01: # 签发机构使用 HTTP-01 的方式进行 acme 协议 (还可用 DNS 方式,acme 协议的目的是证明机器和域名都是属于你的,然后才准许颁发证书)
ingress:
#serviceType: ClusterIP
name: lannengtech-k8s-ingress-lanneng-open-park-third-party # 这个匹配是关键!!! 1. class是指定自动创建的 Ingress 的 ingress class 2. name是指定被自动修改的 Ingress 名称

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: lannengtech-k8s-ingress-lanneng-open-park-third-party
namespace: default
annotations:
# 指定使用nginx做代理
#kubernetes.io/ingress.class: lanneng-park # 已弃用 使用 spec.ingressClassName代替
# add an annotation indicating the issuer to use
cert-manager.io/cluster-issuer: letsencrypt-prod-lanneng-open-park-third-party
acme.cert-manager.io/http01-edit-in-place: "true"

# 后端大文件上传大小
nginx.ingress.kubernetes.io/client-body-buffer-size: 1024m
nginx.ingress.kubernetes.io/proxy-max-temp-file-size: 2048m
# 数据传输大小
nginx.ingress.kubernetes.io/proxy-body-size: 1024m

# 开启CORS跨域请求
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-max-age: "64800"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, DELETE, PATCH, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"

# 配置是否同时支持http和https访问应用
nginx.ingress.kubernetes.io/ssl-redirect: "false"

# 采用了 “漏斗” 算法实现限流 保证服务可用性和被攻击 nginx的限流是一个队列模型。限流连接数为 队列长度+队列处理能力
# 每个IP每秒可以访问的次数 默认乘数为5
nginx.ingress.kubernetes.io/limit-rps: "50"
# 为计算限速漏桶算法的 burst size和 limit-rps 的相乘放大系数 burst为队列长度
nginx.ingress.kubernetes.io/limit-burst-multiplier: "10"
# 配合 limit-window 表示每多少秒全局限速多少次(需要依赖 memcached)
nginx.ingress.kubernetes.io/global-rate-limit: "100000"
nginx.ingress.kubernetes.io/global-rate-limit-window: 1s
# 限制发送给后端服务的发送速率为 多少MB/每秒 rate为队列处理能力
#nginx.ingress.kubernetes.io/limit-rate: 10240
# 发送给后端服务的前 多少MB 数据不进行限速
#nginx.ingress.kubernetes.io/limit-rate-after: 102400
# 白名单 客户端IP源范围要从速率限制中排除。该值是逗号分隔的CIDR列表
#nginx.ingress.kubernetes.io/limit-whitelist:
# 限流超出后的响应码
nginx.ingress.kubernetes.io/configuration-snippet: |
limit_req_status 429;
spec:
ingressClassName: lanneng-park
tls:
- hosts:
- park-foreign-api.pengbocloud.com
secretName: park-foreign-api.pengbocloud.com-tls

rules:
#自定义域名
- host: park-foreign-api.pengbocloud.com
http:
paths:
- path: /
backend:
#服务名称
service:
name: park-saas-foreign-python-service
#服务端口
port:
number: 8201
pathType: Prefix
8 changes: 6 additions & 2 deletions _k8s/letsencrypt/cert-manager-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,29 @@ metadata:
# add an annotation indicating the issuer to use
cert-manager.io/cluster-issuer: letsencrypt-prod
acme.cert-manager.io/http01-edit-in-place: "true"

# 负载均衡算法 如ip_hash
nginx.ingress.kubernetes.io/upstream-hash-by: "$host"
# Session保持配置
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/affinity-mode: "persistent"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
# 后端大文件上传大小

# 后端大文件上传大小 数据传输大小
nginx.ingress.kubernetes.io/client-body-buffer-size: 1024m
nginx.ingress.kubernetes.io/proxy-max-temp-file-size: 2048m
# 数据传输大小
nginx.ingress.kubernetes.io/proxy-body-size: 1024m

# 开启CORS跨域请求
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-max-age: "64800"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, DELETE, PATCH, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"

# 配置是否同时支持http和https访问应用
nginx.ingress.kubernetes.io/ssl-redirect: "false"

# 采用了 “漏斗” 算法实现限流 保证服务可用性和被攻击 nginx的限流是一个队列模型。限流连接数为 队列长度+队列处理能力
# 每个IP每秒可以访问的次数 默认乘数为5
nginx.ingress.kubernetes.io/limit-rps: "50"
Expand Down
3 changes: 1 addition & 2 deletions _nginx/tcpserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

upstream mysql-server {
server 172.16.0.10:4000 weight=1;
server 172.16.0.11:4000 weight=1;
server 172.16.0.12:4000 down;
server 172.16.0.11:4000 down;
}

upstream redis-server {
Expand Down
2 changes: 1 addition & 1 deletion pipelines/demo/Jenkinsfile.panweiji-prod
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ map.put('k8s_credentials_ids', ' ')
map.put('k8s_image_pull_secrets', ' ')

// 项目标签或项目简称
map.put('project_tag', '房产销售')
map.put('project_tag', '潘维吉')

// 是否是生产环境
map.put('is_prod', true)
Expand Down
2 changes: 1 addition & 1 deletion pipelines/epark/Jenkinsfile.lanneng-car-wash-prod
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ map.put('is_before_deploy_notice', false)
// 是否通知变更记录
map.put('is_notice_change_log', true)
// 是否在生产环境发布成功后自动给Git仓库打Tag版本和生成变更记录
map.put('is_git_tag', false)
map.put('is_git_tag', true)
// 是否需要css预处理器sass
map.put('is_need_sass', false)

Expand Down
4 changes: 2 additions & 2 deletions pipelines/epark/Jenkinsfile.lanneng-landing-page-prod
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ map.put('is_git_tag', true)
map.put('is_need_sass', false)

// jenkins分布式构建节点label名称 预配置在jenkins节点管理内
map.put('jenkins_node', 'master')
map.put('jenkins_node_front_end', 'master')
map.put('jenkins_node', 'node-2')
map.put('jenkins_node_front_end', 'node-2')

// 构建环境变量 分别使用Node和Maven关键字加版本号方式 如Maven3.6
map.put('nodejs', 'Node14')
Expand Down
Loading

0 comments on commit 15358ba

Please sign in to comment.