mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-09-05 00:57:15 +00:00
76 lines
2.4 KiB
Templ
76 lines
2.4 KiB
Templ
server {
|
|
listen 8080 default_server;
|
|
root /var/www/html/;
|
|
index index.html;
|
|
|
|
location / {
|
|
try_files $uri $uri/ =404;
|
|
add_header Last-Modified $date_gmt;
|
|
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
|
|
if_modified_since off;
|
|
expires off;
|
|
etag off;
|
|
}
|
|
|
|
location /metrics {
|
|
default_type text/html;
|
|
content_by_lua_block {
|
|
local redis = require "resty.redis"
|
|
local red = redis:new()
|
|
local okredis, errredis = red:connect("unix:/tmp/redis.sock")
|
|
for i, res in ipairs(red:keys("*")) do
|
|
ngx.log(ngx.ERR, res)
|
|
|
|
if string.find(res, "chaos_node_jobs_total_on") then
|
|
node = string.gsub(res, "chaos_node_jobs_total_on_", "")
|
|
metric = "chaos_jobs_node_count{node=\"".. node .."\"}"
|
|
ngx.say(metric .. " " .. red:get(res))
|
|
|
|
elseif string.find(res, "deleted_pods_total_on") then
|
|
namespace = string.gsub(res, "deleted_pods_total_on_", "")
|
|
metric = "deleted_namespace_pods_count{namespace=\"".. namespace .."\"}"
|
|
ngx.say(metric .. " " .. red:get(res))
|
|
else
|
|
ngx.say(res .. " " .. red:get(res))
|
|
end
|
|
end
|
|
}
|
|
}
|
|
|
|
location /kube/kube-linter {
|
|
default_type text/html;
|
|
content_by_lua_block {
|
|
local arg = ngx.req.get_uri_args()
|
|
ngx.req.read_body()
|
|
local request_body = ngx.req.get_body_data()
|
|
local handle = io.popen("/opt/kube-linter-parser.sh " .. arg['k8s_url'] .. " " .. arg['namespace'] .. " " .. arg['pod_name'] .. " " .. arg['token'])
|
|
local result = handle:read("*a")
|
|
ngx.say(result)
|
|
}
|
|
}
|
|
|
|
location /kube/chaos-node {
|
|
default_type text/html;
|
|
access_by_lua_file /tmp/metrics.lua;
|
|
content_by_lua_block {
|
|
local arg = ngx.req.get_uri_args()
|
|
ngx.req.read_body()
|
|
local request_body = ngx.req.get_body_data()
|
|
os.execute("/opt/chaos-node.sh " .. arg['k8s_url'] .. " " .. arg['token'] .. " " .. arg['node_name'] .. " " .. arg['namespace'] .. " &")
|
|
ngx.say('chaos_node started!')
|
|
}
|
|
}
|
|
|
|
location /kube {
|
|
rewrite ^/kube(.*)$ /api$1 break;
|
|
proxy_pass https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS};
|
|
access_by_lua_file /tmp/metrics.lua;
|
|
}
|
|
|
|
location /kube/api {
|
|
rewrite ^/kube/api(.*)$ /api$1 break;
|
|
proxy_pass https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS};
|
|
access_by_lua_file /tmp/metrics.lua;
|
|
}
|
|
}
|