通过ps命令定位到 worker 数量非常多
解决方法:
限定worker数量:worker_processes 4;
Q:为啥会产生这么多worker?
A:在k8s上,nginx 启动的 worker process,并没有遵循我们给 Pod 设置的 limit,而是与 Pod 所在 node 有关。
问题2:nginx worker process exited on signal 9是由于Deployment设定的内存限额太小所致
解决方法:调大requests资源限额
resources: limits: cpu: "2000m" memory: "1Gi" requests: cpu: "1000m" memory: "512Mi"ps:启动4个Worker大约消耗200Mi。
问题3:attempt to index upvalue ‘result_dict’ (a nil value)原因是线上的nginx.conf有相关的定义
而代码层面上没有,加上即可:
借鸡生蛋
如何接入Prometheus监控在OpenResty中接入 Prometheus,https://github.com/knyar/nginx-lua-prometheus
安装依赖 luarocks --tree=http://www.likecs.com/usr/local/openresty/nginx/luarocks install nginx-lua-prometheus 新增配置为nginx/conf/vhosts/project.nginx.conf增加:
lua_shared_dict prometheus_metrics 10M; log_by_lua_block { metric_requests:inc(1, {ngx.var.server_name, ngx.var.status}) metric_latency:observe(tonumber(ngx.var.request_time), {ngx.var.server_name}) } 新增配置文件新增nginx/conf/vhosts/inner.prometheus.nginx.conf
server { listen 8099; location /metrics { content_by_lua_block { metric_connections:set(ngx.var.connections_reading, {"reading"}) metric_connections:set(ngx.var.connections_waiting, {"waiting"}) metric_connections:set(ngx.var.connections_writing, {"writing"}) prometheus:collect() } } } 更新deployment配置 apiVersion: extensions/v1beta1 kind: Deployment metadata: name: ${name} namespace: ${namespace} labels: test-app: test-server spec: replicas: ${replicas} template: metadata: labels: test-app: test-server annotations: # <----------------------- 新增 prometheus.io/scrape: "true" prometheus.io/path: "/metrics" prometheus.io/port: "8099" 总结至此,lua的一个项目容器化完成,中途遇到的问题还是蛮多的,上面也只记录了几个主要的步骤和问题。