阿里云ingress配置时间超时的参数

这篇具有很好参考价值的文章主要介绍了阿里云ingress配置时间超时的参数。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、背景

在使用阿里云k8s集群的时候,内网API网关,刚开始是用的是Nginx,后面又搭建了ingress。
区别于nginx配置,ingress又该怎么设置参数呢?比如http超时时间等等。

本文会先梳理nginx是如何配置,再对比ingress的配置方式。
示例以超时时间的设置。

二、nginx配置

在k8s部署两个节点的Nginx容器
阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java

      containers:
        - env:
            - name: aliyun_logs_nginx-log
              value: /var/log/nginx/*.log
          image: nginx
          imagePullPolicy: Always
          name: xh-nginx
          ports:
            - containerPort: 80
              protocol: TCP
          resources:
            limits:
              cpu: '2'
              memory: 4Gi
            requests:
              cpu: 250m
              memory: 2Gi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /etc/nginx/nginx.conf
              name: nginx
              subPath: nginx.conf
            - mountPath: /etc/nginx/conf.d
              name: nginx-cm
            - mountPath: /var/log/nginx/
              name: volume-k8s-inner-nginx-log
      volumes:
        - configMap:
            defaultMode: 420
            items:
              - key: nginx.conf
                path: nginx.conf
            name: nginx-conf
          name: nginx
        - configMap:
            defaultMode: 420
            name: nginx-cm
          name: nginx-cm
        - hostPath:
            path: /var/log/nginx
            type: Directory
          name: volume-k8s-inner-nginx-log
        - emptyDir: {}
          name: volumn-sls-16578614717160

这里把/etc/nginx/nginx.conf和下面的/etc/nginx/conf.d/*.conf分别挂载到configMap
阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java

1、nginx-conf下的新增了一个子项nginx.conf

对应容器里的文件/etc/nginx/nginx.conf

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java
详情见下:

user  nginx;
worker_processes  auto;

worker_cpu_affinity auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 10240;

events {
    use epoll;
    worker_connections  10240;
}


http {
    underscores_in_headers on;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 传递http header值
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
# 设置log格式
    log_format  access '$proxy_add_x_forwarded_for $time_local $request $request_time "$upstream_response_time" '
                  '$status $body_bytes_sent $host "$http_user_agent" $bytes_sent $request_length "$upstream_addr" ';

    access_log  /var/log/nginx/access.log  access;

    charset  utf-8;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 500m;

    sendfile       on;
    tcp_nopush     on;
    tcp_nodelay    on;

    keepalive_timeout  600;
    server {
        listen       80;
        server_name  nginx_status;
        location /ngx_status {
        stub_status;
                          }
            }
    fastcgi_connect_timeout 600;
    fastcgi_send_timeout 600;
    fastcgi_read_timeout 600;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    include /etc/nginx/conf.d/*.conf;
    }        

2、nginx-cm

对应容器里的文件/etc/nginx/conf.d/*.conf

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java

下面以常见的用户服务为示例:

upstream user-service-cloud-cluster {
  server 172.16.17.9:8081 weight=50 max_fails=2 fail_timeout=10s;
}
server
{
  listen       80;
  server_name  user.xxx.cloud;
  location / {
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
     proxy_pass http://user-service-cloud-cluster;
     proxy_redirect off;
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header HTTP_HOST $host;
     proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
     proxy_set_header HTTP_X_FORWARDED_HOST $host;
     proxy_set_header X-Forwarded-Host $host;
     proxy_set_header X-Forwarded-Server $host;
     proxy_set_header X-Forwarded-HTTPS 0;
  }
  access_log  /var/log/nginx/user-service_cloud_access.log  access;
  error_log  /var/log/nginx/user-service_cloud_error.log;
 }

3、小节

当你修改了nginx的配置,别忘记了进入Nginx容器进行reload,以使配置生效。

nginx -s reload

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java

三、ingress配置

除了已知的一些区别,它和Nginx的一个最大不同是,不用手动去reload才能让配置生效。

同样部署两个ingress节点

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java
建议你使用Helm安装ingress,简单方便。具体就不在本文赘述了。

下面再看下它的yaml详情:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-ingress-ack-ingress-nginx-v1-controller
  namespace: kube-system
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: nginx-ingress
      app.kubernetes.io/name: ack-ingress-nginx-v1
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app.kubernetes.io/component: controller
        app.kubernetes.io/instance: nginx-ingress
        app.kubernetes.io/name: ack-ingress-nginx-v1
    spec:
      containers:
        - args:
            - /nginx-ingress-controller
            - >-
              --publish-service=$(POD_NAMESPACE)/nginx-ingress-ack-ingress-nginx-v1-controller-internal
            - '--election-id=ingress-controller-leader-ack-nginx'
            - '--controller-class=k8s.io/ack-ingress-nginx'
            - '--ingress-class=ack-nginx'
            - >-
              --configmap=$(POD_NAMESPACE)/nginx-ingress-ack-ingress-nginx-v1-controller
            - '--validating-webhook=:8443'
            - '--validating-webhook-certificate=/usr/local/certificates/cert'
            - '--validating-webhook-key=/usr/local/certificates/key'
            - '--v=2'
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: LD_PRELOAD
              value: /usr/local/lib/libmimalloc.so
          image: >-
            registry-vpc.cn-hangzhou.aliyuncs.com/acs/aliyun-ingress-controller:v1.8.0-aliyun.1
          imagePullPolicy: IfNotPresent
          lifecycle:
            preStop:
              exec:
                command:
                  - /wait-shutdown
          livenessProbe:
            failureThreshold: 5
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          name: controller
          ports:
            - containerPort: 80
              name: http
              protocol: TCP
            - containerPort: 443
              name: https
              protocol: TCP
            - containerPort: 8443
              name: webhook
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          resources:
            requests:
              cpu: 100m
              memory: 90Mi
          securityContext:
            allowPrivilegeEscalation: true
            capabilities:
              add:
                - NET_BIND_SERVICE
              drop:
                - ALL
            runAsUser: 101
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /usr/local/certificates/
              name: webhook-cert
              readOnly: true
            - mountPath: /etc/localtime
              name: localtime
              readOnly: true
      dnsPolicy: ClusterFirst
      initContainers:
        - command:
            - /bin/sh
            - '-c'
            - |
              if [ "$POD_IP" != "$HOST_IP" ]; then
              mount -o remount rw /proc/sys
              sysctl -w net.core.somaxconn=65535
              sysctl -w net.ipv4.ip_local_port_range="1024 65535"
              sysctl -w kernel.core_uses_pid=0
              fi
          env:
            - name: POD_IP
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.podIP
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.hostIP
          image: 'registry-vpc.cn-hangzhou.aliyuncs.com/acs/busybox:v1.29.2'
          imagePullPolicy: IfNotPresent
          name: init-sysctl
          resources: {}
          securityContext:
            capabilities:
              add:
                - SYS_ADMIN
              drop:
                - ALL
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      nodeSelector:
        kubernetes.io/os: linux
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccount: nginx-ingress-ack-ingress-nginx-v1
      serviceAccountName: nginx-ingress-ack-ingress-nginx-v1
      terminationGracePeriodSeconds: 300
      tolerations:
        - effect: NoSchedule
          key: node-role.alibabacloud.com/addon
          operator: Exists
      volumes:
        - name: webhook-cert
          secret:
            defaultMode: 420
            secretName: nginx-ingress-ack-ingress-nginx-v1-admission
        - hostPath:
            path: /etc/localtime
            type: File
          name: localtime

这里使用了一个初始化容器initContainers,它会对系统做一个个性化配置。

sysctl -w net.core.somaxconn=65535
sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w kernel.core_uses_pid=0

其次,HOST_IP和POD_IP都从K8s环境变量中读取,因为它们是动态的,非固定不变。

必要的健康检测,配置了livenessProbe和readinessProbe,详情见上。

1、configMap配置

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java
日志格式,见下:
阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java
其他的配置这里就不一一列举,总之,它支持你通过变量进行配置就行。

它就对应上文的nginx.conf文件。

2、创建Ingress路由

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java

操作比较简单,下面要切入到本文的重点。

四、Ingress设置超时时间

要说Ingress如何设置超时时间前,先看一看nginx是如何设置。

默认是60秒,现在业务上有需求调整为600秒。
请看下文的具体配置:

1、nginx配置

upstream xxx-cloud-cluster {
  server 172.16.17.6:8080 weight=9 max_fails=2 fail_timeout=10s;
}
server
{
  listen       80;
  server_name  image-xxx.xx.cloud;
  location / {
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
     proxy_pass http://xxx-cloud-cluster;
     proxy_redirect off;
     proxy_set_header Host $host;
     # 增加下面三行
     proxy_connect_timeout 600;
     proxy_send_timeout 600;
     proxy_read_timeout 600;
     
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header HTTP_HOST $host;
     proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
     proxy_set_header HTTP_X_FORWARDED_HOST $host;
     proxy_set_header X-Forwarded-Host $host;
     proxy_set_header X-Forwarded-Server $host;
     proxy_set_header X-Forwarded-HTTPS 0;
  }
  access_log  /var/log/nginx/xxx_access.log  access;
  error_log  /var/log/nginx/xxx_error.log;
 }

2、ingress配置

参数设置通过注解配置:
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java

阿里云ingress配置时间超时的参数,阿里云,nginx,云原生,架构,kubernetes,java

yaml详情见下:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-connect-timeout: '600'
    nginx.ingress.kubernetes.io/proxy-read-timeout: '600'
    nginx.ingress.kubernetes.io/proxy-send-timeout: '600'
  labels:
    ingress-controller: nginx
  name: image-xxx
  namespace: java-service
spec:
  ingressClassName: ack-nginx
  rules:
    - host: image.xxx.cloud
      http:
        paths:
          - backend:
              service:
                name: image-xxx
                port:
                  number: 8080
            path: /
            pathType: ImplementationSpecific

五、总结

这里只是以设置超时时间为例,讲述k8s容器部署的Nginx和ingress,如何设置一定自定义的参数配置。

当然,这里没有讲述怎么安装它们,更多的是梳理了一下如何配置,侧重于使用这块。文章来源地址https://www.toymoban.com/news/detail-787259.html

到了这里,关于阿里云ingress配置时间超时的参数的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • K8s的ingress-nginx配置https

    在另一台机器上配置hosts解析www.yaoyao.com,然后访问 curl --cacert tls.crt https://www.yaoyao.com:10443 这里的10443端口是ingress-nginx-controller服务暴露的nodeport端口

    2024年02月07日
    浏览(31)
  • axios 统一配置请求超时时间

    你可以通过配置 axios 的实例来统一设置请求的超时时间。以下是一个示例: 首先,安装 axios(如果还没有安装): 然后,在你的 Vue 项目中,你可以创建一个 axios 的实例,并设置默认的超时时间,然后将它应用到所有的请求。例如,你可以在项目的某个地方(例如 main.js )

    2024年02月03日
    浏览(31)
  • 关于Nginx的超时timeout配置

      本文主要介绍了Nginx的超时timeout配置详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧 本文介绍 Nginx 的 超时(timeout)配置。分享给大家,具体如下: Nginx 处理的每个请求均有相应的超时设置。如果做好这些超时时间的限定,判定

    2024年02月07日
    浏览(26)
  • 【java】Spring Cloud --Feign Client超时时间配置以及单独给某接口设置超时时间方法

    FeignClient面对服务级有三种超时时间配置 feign配置是在ribbon配置的基础上做了扩展,可以支持服务级超时时间配置,所以,feign配置和ribbon配置的效果应该是一样的。 SpringCloud对这两种配置的优先级顺序如下: Feign局部配置 Feign全局配置 Ribbon局部配置 Ribbon全局配置 在feign-co

    2024年02月12日
    浏览(38)
  • Kafka消费者常用超时时间配置

    https://blog.csdn.net/BHSZZY/article/details/126757295 //心跳超时时间(session超时时间)增加成25秒(之前项目设置了15秒) spring.kafka.properties.session.timeout.ms = 25000 //每次拉取的消息减少为20(之前是默认值500) spring.kafka.consumer.max-poll-records=20 //消息消费超时时间增加为10分钟 spring.kafka.p

    2024年02月03日
    浏览(84)
  • Feign、Ribbon、Hystrix(铁三角)以及三者超时时间配置 Feign 如何设置超时时间(connectionTimeout、readTimout

    在微服务架构中很多功能都需要调用多个服务才能完成某一项功能,一个成熟的微服务集群,内部调用必然依赖一个好的 RPC 框架,比如:基于 Http 协议的  Feign ,基于私有 tcp 协议的  Dubbo   1. Feign 是什么 Feign 是Spring Cloud Netflix组件中的轻量级Restful的 HTTP 服务客户端,实现

    2024年02月11日
    浏览(32)
  • springboot小知识:配置feign服务超时时间

    背景:当前项目通过feign服务调用了其他两个项目的接口,但是由于特殊需求,需要调整某一个项目的feign服务的默认超时时间: 默认连接超时10秒,默认读取超时时间 60秒 1.找到定义的FeignClient 2.根据FeignClient定义的名称test-center修改配置文件,如下: 注意:配置中间的test

    2024年02月06日
    浏览(45)
  • nginx 多层代理 + k8s ingress 后端服务获取客户真实ip 配置

    1.nginx http 七层代理 修改命令空间: namespace: nginx-ingress : configmap:nginx-configuration 添加如上配置 compute-full-forwarded-for: “true” forwarded-for-header: X-Forwarded-For use-forwarded-headers: “true” 即可; 2. nginx stream 4层代理: nginx 需要编译增加–with-stream_realip_module模块,然后对应的server块

    2024年02月08日
    浏览(37)
  • 【ArchSummit】阿里云原生微服务架构治理最佳实践

      前言 📫 作者简介 :小明java问道之路,专注于研究 Java/ Liunx内核/ C++及汇编/计算机底层原理/源码,就职于大型金融公司后端高级工程师,擅长交易领域的高安全/可用/并发/性能的架构设计与演进、系统优化与稳定性建设。 📫 热衷分享,喜欢原创~ 关注我会给你带来一些

    2024年02月02日
    浏览(70)
  • 【API接口工具】postman设置超时时间、请求等默认配置

    Postman 会自动为某些设置选择默认值,以便您可以开始工作。根据您的用例随时更改设置或自定义您的 Postman 体验。 要更改 Postman 中的设置,请选择 设置图标 标题中的设置图标,然后选择设置。在 Postman 桌面应用程序中,您还可以选择⌘+逗号 (,)或Ctrl+逗号 (,) 使用“General”

    2024年02月08日
    浏览(44)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包