k8s nginx controller中日志切片配置

只需要添加如下信息至configmap

apiVersion: v1
data:
  compute-full-forwarded-for: "true"
  enable-real-ip: "true"
  keep-alive-requests: "5000"
  log-format-upstream: '{"time": "$time_iso8601", "k8s_service_name":"$service_name",
    "remote_addr": "$proxy_protocol_addr", "x_forward_for": "$proxy_add_x_forwarded_for",
    "request_id": "$req_id", "remote_user": "$remote_user", "bytes_sent": $bytes_sent,
    "request_time": $request_time, "status": $status, "vhost": "$host", "request_proto":
    "$server_protocol", "path": "$uri", "request_query": "$args", "request_length":
    $request_length, "duration": $request_time,"method": "$request_method", "http_referrer":
    "$http_referer", "http_user_agent": "$http_user_agent" }'
  server-snippet: |
    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") {
        set $year $1;
        set $month $2;
        set $day $3;
        set $hour $4;
        set $minutes $5;
        set $seconds $6;
    }
    access_log  /var/log/nginx/access_log_$ingress_name-$year-$month-$day-$hour.log upstreaminfo  if=$loggable;
  upstream-keepalive-connections: "1000"
  use-forwarded-headers: "true"
kind: ConfigMap
metadata:
  annotations:
    meta.helm.sh/release-name: ingress-nginx
    meta.helm.sh/release-namespace: ingress-nginx
  creationTimestamp: "2021-04-08T10:09:29Z"
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/version: 0.44.0
    helm.sh/chart: ingress-nginx-3.26.0
  name: ingress-nginx-controller
  namespace: ingress-nginx
  resourceVersion: "6564521"
  selfLink: /api/v1/namespaces/ingress-nginx/configmaps/ingress-nginx-controller
  uid: 74f466c8-5d0e-4b27-bc96-e1a92d75113f

  

上一篇:kubernetes ingress更改日志格式


下一篇:阿里云kubernetes上搭建Yapi服务