kubernetes ingress配置上传文件大小限制

avatar 2021年5月31日18:19:15 评论 4,134 次浏览

在k8s中,我们上传针对服务中出现的上传文件中定义的上传文件大小限制,默认是没有限制,但是大小是1m,超过1m就会出现无法上传的问题,这里我们说一下如何在不影响用户使用的前提下修改ingress的上传大小限制。首先,我们要理解的是服务的负载均衡是通过ingress请求到服务,然后在服务上一层加了一个类似映射规则,ingress Controller通过监听ingress这个api对象里的规则转化成nginx的配置,所以,我们需要在nginx里配置上传文件的大小。看先一下我的nginx。

[root@www.wulaoer.org ~]# kubectl describe ingress -n beagle-prod prod-m
Name:             prod-m
Namespace:        beagle-prod
Address:          8.131.58.57
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
  beagle-prod-ssl terminates www.wulaoer.org   #域名
Rules:
  Host               Path  Backends
  ----               ----  --------
  www.wulaoer.org
                     /   beago-shaky:80 (10.16.12.186:80)
Annotations:         field.cattle.io/creatorId: user-8l7lk
                     field.cattle.io/ingressState:
                       {"YmVhZ2xlLXByb2Qtc3Ns":"p-l9gqp:beagle-prod-ssl","cHJvZC1tL2JlYWdsZS1wcm9kL20ueGlhb2xpZXF1YW4ubmV0Ly8vODA=":""}
                     field.cattle.io/publicEndpoints:
                       [{"addresses":["18.13.5.57"],"port":443,"protocol":"HTTPS","serviceName":"beagle-prod:beago-shaky","ingressName":"beagle-prod:prod-m","ho...
                     nginx.ingress.kubernetes.io/service-weight:
                     nginx.ingress.kubernetes.io/ssl-redirect: true
Events:              <none>

这里没有定义文件上传大小,我们可以修改一下Annotations下添加nginx.ingress.kubernetes.io/proxy-body-size: "5M",这样不需要重新启动就会自动的生效,上传限制在5M以内的大小文件。

[root@www.wulaoer.org ~]# kubectl edit ingress -n beagle-prod prod-m
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    field.cattle.io/creatorId: user-8l7lk
    field.cattle.io/ingressState: '{"YmVhZ2xlLXByb2Qtc3Ns":"p-l9gqp:beagle-prod-ssl","cHJvZC1tL2JlYWdsZS1wcm9kL20ueGlhb2xpZXF1YW4ubmV0Ly8vODA=":""}'
    field.cattle.io/publicEndpoints: '[{"addresses":["18.13.5.57"],"port":443,"protocol":"HTTPS","serviceName":"beagle-prod:beago-shaky","ingressName":"beagle-prod:prod-m","hostname":"www.wulaoer.org","path":"/","allNodes":false}]'
    nginx.ingress.kubernetes.io/service-weight: ""
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/proxy-body-size: "5M"    #增加了上传大小限制

保存就会生效,后面就可以自己验证一下了,这里就不叙述了,主要是编辑使用方法,以及对ingress的理解。

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: