探針分類:
liveness probe
readiness probe
startup probe
Liveness Probe:用于檢查容器是否還在運(yùn)行。如果 Liveness Probe 失敗,Kubernetes 會(huì)殺死容器,然后根據(jù)你的重啟策略來決定是否重新啟動(dòng)容器。常見的做法是使用與 Readiness Probe 相同的低成本 HTTP 端點(diǎn),但是設(shè)置更高的?
failureThreshold
,這樣可以確保在 Pod 被強(qiáng)制殺死之前,它會(huì)被觀察到為 not-ready 一段時(shí)間。Readiness Probe:用于檢查容器是否準(zhǔn)備好接受流量。一個(gè) Pod 被認(rèn)為是 ready 的,當(dāng)且僅當(dāng)它的所有容器都是 ready 的。這個(gè)信號(hào)的一個(gè)用途是控制哪些 Pod 被用作 Service 的后端。當(dāng)一個(gè) Pod 不是 ready 的,它會(huì)從 Service 的負(fù)載均衡器中移除。
Startup Probe:用于檢查容器應(yīng)用程序是否已經(jīng)啟動(dòng)。如果配置了這樣的探針,那么在它成功之前,Liveness Probe 和 Readiness Probe 不會(huì)開始,確保這些探針不會(huì)干擾應(yīng)用程序的啟動(dòng)。這可以用于對(duì)慢啟動(dòng)的容器進(jìn)行 Liveness 檢查,避免它們?cè)趩?dòng)并運(yùn)行之前被 kubelet 殺死。
探測(cè)方式
HTTPGetAction
TCPSocketAction
ExecAction
每種探針都可以使用以下三種方式之一進(jìn)行檢查:
HTTP GET:對(duì)容器的一個(gè) HTTP 服務(wù)器發(fā)起一個(gè) GET 請(qǐng)求。如果服務(wù)器返回的狀態(tài)碼在 200 到 399 之間,那么探針就是成功的。
TCP Socket:嘗試打開容器的一個(gè) TCP 端口。如果端口已經(jīng)打開,那么探針就是成功的。
Exec:在容器中執(zhí)行一個(gè)命令。如果命令返回 0,那么探針就是成功的。
?
ERROR: The Pod "app" is invalid: spec.containers[0].livenessProbe.successThreshold: Invalid value: 3: must be 1
對(duì)于 Liveness 探針,
successThreshold
?的值必須為 1。這是因?yàn)?Liveness 探針只需要一次成功的探測(cè)就能確定容器是存活的。所以,你需要將?successThreshold
?的值改為 1。
apiVersion: v1
kind: Pod
metadata:
name: 'app'
labels:
name: 'zs'
age: '18'
spec:
containers:
- name: 'probe-po'
image: nginx:1.14.2
livenessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 5
failureThreshold: 3
successThreshold: 1
這時(shí) 如果將 index.html 改成 index1.html?
?livenessProbe 采用 tcpSocket
apiVersion: v1
kind: Pod
metadata:
name: 'app'
labels:
name: 'zs'
age: '18'
spec:
containers:
- name: 'probe-po'
image: nginx:1.14.2
livenessProbe:
# httpGet:
# path: /index1.html
# port: 80
# initialDelaySeconds: 5
# periodSeconds: 5
# timeoutSeconds: 5
# failureThreshold: 3
# successThreshold: 1
tcpSocket:
port: 80
periodSeconds: 5
successThreshold: 1
failureThreshold: 3
livenessProbe 采用 exec
apiVersion: v1
kind: Pod
metadata:
name: 'app'
labels:
name: 'zs'
age: '18'
spec:
containers:
- name: 'probe-po'
image: nginx:1.14.2
livenessProbe:
# httpGet:
# path: /index1.html
# port: 80
# initialDelaySeconds: 5
# periodSeconds: 5
# timeoutSeconds: 5
# failureThreshold: 3
# successThreshold: 1
# tcpSocket:
# port: 89
# periodSeconds: 5
# successThreshold: 1
# failureThreshold: 3
exec:
command: ['cat', '/usr/share/nginx/html/index.html']
# - cat
# - /usr/share/nginx/html/index.html
successThreshold: 1
failureThreshold: 3
timeoutSeconds: 3
periodSeconds: 3
改成 index1.html
文章來源:http://www.zghlxwxcb.cn/news/detail-860499.html
配置 livenessProbe readinessProbe startupProbe
apiVersion: v1
kind: Pod
metadata:
name: 'app'
labels:
name: 'zs'
age: '18'
spec:
containers:
- name: 'probe-po'
image: nginx:1.14.2
livenessProbe:
# httpGet:
# path: /index1.html
# port: 80
# initialDelaySeconds: 5
# periodSeconds: 5
# timeoutSeconds: 5
# failureThreshold: 3
# successThreshold: 1
# tcpSocket:
# port: 89
# periodSeconds: 5
# successThreshold: 1
# failureThreshold: 3
exec:
command: ['cat', '/usr/share/nginx/html/index1.html']
# - cat
# - /usr/share/nginx/html/index.html
successThreshold: 1
failureThreshold: 3
timeoutSeconds: 3
periodSeconds: 3
readinessProbe:
httpGet:
path: /index.html
port: 80
failureThreshold: 3
successThreshold: 1
timeoutSeconds: 3
periodSeconds: 3
startupProbe:
httpGet:
path: /index.html
port: 80
failureThreshold: 3
successThreshold: 1
timeoutSeconds: 3
periodSeconds: 3
文章來源地址http://www.zghlxwxcb.cn/news/detail-860499.html
到了這里,關(guān)于K8S哲學(xué) - probe 探針的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!