我在获取 kubernetes livenessProbe exec 命令来处理环境变量时遇到困难。\n我的目标是让 liveness 探针监视 pod 上的内存使用情况并执行 httpGet 运行状况检查。
\n“如果容器内存使用量超过资源限制的 90% 或 http 响应代码/health失败,则探测应该失败。”
活性探针配置如下:
\n\nlivenessProbe:\n exec:\n command:\n - sh\n - -c\n - |-\n "used=$(awk '{ print int($1/1.049e+6) }' /sys/fs/cgroup/memory/memory.usage_in_bytes);\n thresh=$(awk '{ print int( $1 / 1.049e+6 * 0.9 ) }' /sys/fs/cgroup/memory/memory.limit_in_bytes);\n health=$(curl -s -o /dev/null --write-out "%{http_code}" http://localhost:8080/health);\n if [[ ${used} -gt ${thresh} || ${health} -ne 200 ]]; then exit 1; fi"\n initialDelaySeconds: 240\n periodSeconds: 60\n failureThreshold: 3\n timeoutSeconds: 10\n\nRun Code Online (Sandbox Code Playgroud)\n如果我执行到(ubuntu)pod并运行这些命令,它们都可以正常工作并完成工作。 …