首页 > 系统相关 >ingress-nginx的日志落地

ingress-nginx的日志落地

时间:2023-03-29 13:24:15浏览次数:42  
标签:ingress log nginx controller io 日志 name

配置Nginx-Ingress

这里将NG的日志落盘,便于处理。

(1)、修改ConfigMap,如下:

# Source: ingress-nginx/templates/controller-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    helm.sh/chart: ingress-nginx-2.0.3
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.32.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
data:
  compute-full-forwarded-for: 'true'
  enable-underscores-in-headers: 'true'
  client_max_body_size: "100m"
  proxy_body_size: "100m"
  access-log-path: /var/log/nginx/access.log
  log-format-escape-json: "true"
  log-format-upstream: '{"timestamp": "$time_iso8601", "requestID": "$req_id", "proxyUpstreamName":
    "$proxy_upstream_name","host": "$host","body_bytes_sent": "$body_bytes_sent","proxyAlternativeUpstreamName": "$proxy_alternative_upstream_name","upstreamStatus":
    "$upstream_status", "geoip_country_code": "$geoip_country_code","upstreamAddr": "$upstream_addr","request_time":
    "$request_time","httpRequest":{"requestMethod": "$request_method", "requestUrl":
    "$request_uri", "status": $status,"requestSize": "$request_length", "responseSize":
    "$upstream_response_length", "userAgent": "$http_user_agent", "remoteIp": "$remote_addr",
    "referer": "$http_referer", "latency": "$upstream_response_time", "protocol":"$server_protocol"}}'

 

(2)修改NG的deployment,主要增加如下配置

# Source: ingress-nginx/templates/controller-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    helm.sh/chart: ingress-nginx-2.0.3
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.32.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
......
      initContainers:
      - name: adddirperm
        image: busybox
        command:
        - /bin/sh
        - -c
        - chown -R ${USER_ID}:${USER_ID} ${LOG_DIR}
        env:
        - name: LOG_DIR
          value: /var/log/nginx
        - name: USER_ID
          value: "101"
        volumeMounts:
        - name: logdir
          mountPath: /var/log/nginx
      containers:
        - name: controller
          image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.32.0
          imagePullPolicy: IfNotPresent
          lifecycle:
            preStop:
              exec:
                command:
                  - /wait-shutdown
          args:
            - /nginx-ingress-controller
            - --publish-service=ingress-nginx/ingress-nginx-controller
            - --election-id=ingress-controller-leader
            - --ingress-class=nginx
            - --configmap=ingress-nginx/ingress-nginx-controller
            - --validating-webhook=:8443
            - --validating-webhook-certificate=/usr/local/certificates/cert
            - --validating-webhook-key=/usr/local/certificates/key
            - --log_dir=/var/log/nginx
            - --logtostderr=false
......
          volumeMounts:
            - name: webhook-cert
              mountPath: /usr/local/certificates/
              readOnly: true
            - name: logdir
              mountPath: /var/log/nginx
          resources:
            requests:
              cpu: 100m
              memory: 90Mi
      serviceAccountName: ingress-nginx
      terminationGracePeriodSeconds: 300
      volumes:
......
        - name: logdir
          hostPath:
            path: /var/log/nginx
            type: DirectoryOrCreate

 

重新创建后即可在本地的/var/log/nginx下查找到日志。

 

标签:ingress,log,nginx,controller,io,日志,name
From: https://www.cnblogs.com/fengjian2016/p/17268548.html

相关文章

  • k8s的 Nginx Ingress 调优
    内核参数调优我们先看看通过内核的哪些参数能够提高Ingress的性能。保证在高并发环境下,发挥Ingress的最大性能。调大全连接队列的大小TCP全连接队列的最大值取决于som......
  • nginx配置vue打包npm build的静态页面
    nginx配置vue项目server{listen8081;server_name10.8.8.8;indexindex.html;root/home/www/crm/vue/dist;#SSL-STARTSSL相关配置,请勿删......
  • 一篇搞定Nginx功能
    from:https://mp.weixin.qq.com/s/yF5h7dslESaa3Gt5rE6IbQ 引言一、性能怪兽-Nginx概念深入浅出二、Nginx环境搭建三、Nginx反向代理-负载均衡四、Nginx动静分离......
  • Mysql通用查询日志(General Query Log)解析
    文档课题:Mysql通用查询日志(GeneralQueryLog)解析.数据库:mysql8.0.111、概念知识说明:通用查询日志用来记录用户的所有操作,包括启动和关闭MySQL服务、更新语句、查询语......
  • 一文剖析:LVS/Nginx/HAProxy原理及应用场景
    负载均衡已经发展成为网络架构中的基础核心组件,消除了服务器单点故障,可以进行请求流量分流,提升冗余,保证服务器的稳定性。在开源的软件负载均衡中,应用最为广泛的有LVS、Nginx......
  • 第九天(nginx-第三篇--------nginx的相关总结)
    1.1、Nginx​Nginx(enginex)是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点......
  • oracle 离线分析其他库的归档日志
    oracle数据库是可以离线分析其他库的归档日志的,比如想分析生产库的归档日志,可以将其拿到测试库上来分析,以免影响生产库的性能。dictory模式:将数据库的数据字典抽取到操作......
  • 局域网机器配置Nginx正向代理访问外网服务
    1.正向代理1.1简介https://blog.csdn.net/wkh___/article/details/113807080?spm=1001.2014.3001.5506https://www.cnblogs.com/yanjieli/p/15229907.html1.2请求......
  • 如何在容器服务 ACK 玩转 MSE Ingress
    作者:扬少随着容器和Kubernetes技术的兴起,集群入口流量管理方式逐渐被Ingress通用化和标准化。入口网关的标准化制定将入口流量管理与网关的实现解耦,不仅促进了各种Ingr......
  • 如何在容器服务 ACK 玩转 MSE Ingress
    作者:扬少随着容器和Kubernetes技术的兴起,集群入口流量管理方式逐渐被Ingress通用化和标准化。入口网关的标准化制定将入口流量管理与网关的实现解耦,不仅促进了各种......