[英]How does kubelet interpret the results of healthcheck end point?
Below is the Pod resource type for deploying a container:下面是用于部署容器的 Pod 资源类型:
apiVersion: v1
kind: Pod
metadata:
name: my-container
labels:
app: myapp
rel: stable
spec:
containers:
- name: my-container
image: myimage:latest
resources:
limits:
memory: "128Mi" #128 MB
cpu: "200m" #200 millicpu (.2 cpu or 20% of the cpu)
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /health-check
port: 80
initialDelaySeconds: 15
timeoutSeconds: 2 # Default is 1
periodSeconds: 5 # Default is 10
failureThreshold: 1 # Default is 3
readinessProbe:
httpGet:
path: /health-check
port: 80
initialDelaySeconds: 3
periodSeconds: 5 # Default is 10
failureThreshold: 1 # Default is 3
the /health-check
end point returns http status 200
status with below json: /health-check
端点使用以下 json 返回 http 状态200
状态:
{
"details": {
"app": {
"framework": "gin",
"name": "my-app-local",
"version": "v1"
},
"databases": [
{
"database": "my_db",
"host": "localhost",
"name": "mysql",
"status": "Normal"
}
]
},
"status": "Normal"
}
Given above Pod yaml, how does kubelet read the status
value for "databases"
& "app"
?上面给出了 Pod yaml,kubelet 如何读取"databases"
和"app"
的status
值? as part of livenessProbe
or readinessProbe
, to ensure container is running fine.作为livenessProbe
或readinessProbe
一部分,以确保容器运行良好。
It does not work like that, it checks the return code of http requests.它不是那样工作的,它会检查 http 请求的返回码。 Here is snippet from the documentation(port 80 in this case):这是文档中的片段(在这种情况下为端口 80):
To perform a probe, the kubelet sends an HTTP GET request to the server that is running in the container and listening on port 8080.为了执行探测,kubelet 向在容器中运行并侦听端口 8080 的服务器发送 HTTP GET 请求。
If the handler for the server's /healthz path returns a success code, the kubelet considers the container to be alive and healthy.如果服务器的 /healthz 路径的处理程序返回成功代码,则 kubelet 会认为容器处于活动状态且健康。 If the handler returns a failure code, the kubelet kills the container and restarts it.如果处理程序返回失败代码,kubelet 将终止容器并重新启动它。 Any code greater than or equal to 200 and less than 400 indicates success.任何大于或等于 200 且小于 400 的代码都表示成功。 Any other code indicates failure任何其他代码表示失败
If you really need to read json
response,then do curl
and use jq
or grep
to find the status in json
response.如果你真的需要读取json
响应,那么做curl
并使用jq
或grep
在json
响应中查找状态。 For jq
something like jq '.details.databases[].status'
对于jq
类似jq '.details.databases[].status'
livenessProbe:
exec:
command:
- sh
- -c
- curl --silent http://localhost:80/healthz | grep .......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.