潍坊做网站的,怎样查看网站关键词,wordpress 媒体库不显示,开个电商公司需要多少钱点击上方蓝色字体#xff0c;关注我们读完需 8 分钟速读需 4 分钟k8s集群默认安装的ingress-nginx直接投入测试或生产使用#xff0c;其不合适的配置参数可能会导致一些访问报错。例如#xff1a;“413 Request Entity Too Large”“503 Service Unavailable”此时我们就需要… 点击上方蓝色字体关注我们读完需 8 分钟速读需 4 分钟k8s集群默认安装的ingress-nginx直接投入测试或生产使用其不合适的配置参数可能会导致一些访问报错。例如“413 Request Entity Too Large”“503 Service Unavailable”此时我们就需要调整ingress-nginx的配置参数来解决问题有以下三种方式ConfigMap使用ConfigMap设置Nginx的全局配置文件Annotations使用Annotations设置特定的Server的配置文件如某个hello.test.cnCustom Template使用模板设置更多的特定Server的配置文件在此只介绍下比较常见的ConfigMap、Annotations两种方式。需求在此主要以解决以下两个问题为例“413 Request Entity Too Large”此问题为上传文件过大导致nginx默认限制为1M可以通过调整client_max_body_size参数解决。upstream超时upstream超市可能会导致502、503、504等问题nginx默认超时时间为60s可以通过设置proxy_read_timeout、proxy_connect_timeout、proxy_send_timeout参数解决。ConfigMap1. 默认配置默认ingress-nginx的ConfigMap有以下三种并且数据都为空# 默认的三种ConfigMap# kubectl get cm -n ingress-nginxNAME DATA AGEingress-controller-leader-nginx 0 10dnginx-configuration 0 10dtcp-services 0 10dudp-services 0 10d# ConfigMap定义# vim mandatory# 截取ConfigMap部分---kind: ConfigMapapiVersion: v1metadata: name: nginx-configuration namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx---kind: ConfigMapapiVersion: v1metadata: name: tcp-services namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx---kind: ConfigMapapiVersion: v1metadata: name: udp-services namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx其中三种ConfigMap都没有Data设置因此数据定义都为空nginx-ingress-controller分别引用nginx-configuration、 tcp-services、 udp-services三个ConfigMap。2.自定义设置调整参数我们需要选择对应的ConfigMap经过测试需要选择nginx-configuration。# vim global_configmap.yaml# ingress-nginx 全局配置文件apiVersion: v1kind: ConfigMapmetadata: name: nginx-configuration namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginxdata: proxy-connect-timeout: 300 proxy-read-timeout: 300 proxy-send-timeout: 300 proxy-body-size: 200m# 应用后nginx会自动reload生效kubectl apply -f global_configmap.yaml# 检查配置文件kubectl exec -it nginx-ingress-controller-gmzq6 -n ingress-nginx -- cat /etc/nginx/nginx.conf注意使用nginx-configuration而不是tcp-services和udp-services。经测试按照官网https://kubernetes.github.io/ingress-nginx/examples/customization/custom-configuration/设置ConfigMap使用ingress-nginx-controller是不生效的因为没有ingress-nginx-controller这个ConfigMap需要使用nginx-configuration。$ cat configmap.yamlapiVersion: v1data: proxy-connect-timeout: 10 proxy-read-timeout: 120 proxy-send-timeout: 120kind: ConfigMapmetadata: name: ingress-nginx-controller在此我将全局配置文件单独列出也可以将其合并到mandatory.yaml中。AnnotationsConfigMap适用于全局配置但是有时我们只需要针对某个特定的站点设置此时就需要用到Annotations。例如要对hello.test.cn 这个站设置client_max_body_size解决上传文件太大问题。# vim hellworld.yaml# 单独设置IngressapiVersion: extensions/v1beta1kind: Ingressmetadata: name: helloworld namespace: test annotations: nginx.ingress.kubernetes.io/proxy-body-size: 300mspec: rules: - host: hello.test.cn http: paths: - path: / backend: serviceName: helloworld servicePort: 8080# 应用# kubectl apply -f helloworld.yaml# 验证# kubectl exec -it nginx-ingress-controller-gmzq6 -n ingress-nginx -- cat /etc/ngclient_max_body_size 300m;此时client_max_body_size只针对hello.test.cn 这个server生效其他server仍然使用的是全局配置文件。总结在ingress-nginx的配置文件/etc/nginx/nginx.conf中指定了Global filters、TCP services、UDP services区域应该分别对应三个ConfigMap。熟悉了ingress-nginx的自定义配置后我们就可以灵活修改配置参数了。k8s node节点停机维护pod如何迁移K8SJenkins实现SpringBoot项目的CI/CDJenkins扩展共享库进阶Ventoy:新一代多系统启动U盘解决方案面对中小企业的开源运维平台spugDocker动态构建Jenkins Slave关注我们