探針的使用
kubectl edit deploy -n kube-system coredns
livenessprobe 的使用
livenessProbe:
failureThreshold: 5
httpGet:
path: /health
port: 8080
scheme: HTTP
initialDelaySeconds: 60
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
readinessProbe
readinessProbe:
failureThreshold: 3
httpGet:
path: /ready
port: 8181
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
kubectl edit po nginx
kubectl describe po nginx-daemon
最下面有容器啟動時候相關(guān)日志
容器探針啟動實驗1-啟動探針的使用-startupprobe
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 20s default-scheduler Successfully assigned default/my-pod1 to ha2.example.local
Normal Pulled 20s kubelet Container image "nginx:1.7.9" already present on machine
Normal Created 20s kubelet Created container nginx
Normal Started 20s kubelet Started container nginx
Warning Unhealthy 4s (x2 over 14s) kubelet Startup probe failed: HTTP probe failed with statuscode: 404
[root@kubeadm-master1 test]# kubectl get pod
NAME READY STATUS RESTARTS AGE
client 1/1 Running 0 48d
my-pod 1/1 Running 0 7d23h
my-pod1 0/1 Running 0 37s
net-test1 1/1 Running 133 55d
net-test2 1/1 Running 13 55d
nginx-deployment-67dfd6c8f9-5s6nz 1/1 Running 1 55d
tomcat-deployment-6c44f58b47-4pz6d 1/1 Running 1 55d
[root@kubeadm-master1 test]# kubectl get pod
NAME READY STATUS RESTARTS AGE
client 1/1 Running 0 48d
my-pod 1/1 Running 0 7d23h
my-pod1 0/1 Running 0 42s
net-test1 1/1 Running 133 55d
net-test2 1/1 Running 13 55d
nginx-deployment-67dfd6c8f9-5s6nz 1/1 Running 1 55d
tomcat-deployment-6c44f58b47-4pz6d 1/1 Running 1 55d
[root@kubeadm-master1 test]# cat nginx-po.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod1
labels:
type: app
test: "1.0.0"
namespace: default
spec:
containers:
- name: nginx
image: nginx:1.7.9
imagePullPolicy: IfNotPresent
command:
- nginx
- -g
- 'daemon off;'
workingDir: /usr/share/nginx/html
ports:
- name: http
containerPort: 80
protocol: TCP
env:
- name: JVM_OPTS
value: '-Xms128m -Xmx128m'
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 200m
memory: 256Mi
startupProbe:
httpGet:
path: /api/path
port: 80
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
restartPolicy: OnFailure
Liveness Probes 和 Readiness Probes
用于檢查容器是否還在運行。如果 liveness 探針失敗,Kubernetes 將殺死容器,并根據(jù)其重啟策略來處理。
用于檢查容器是否已經(jīng)準備好接收流量。如果 readiness 探針失敗,Kubernetes 將不會將流量路由到該容器。
定義了一個 startupProbe,它在容器啟動后通過 HTTP GET 請求檢查 /api/path 端點?,F(xiàn)在我們將添加 livenessProbe 和 readinessProbe。
一個 livenessProbe 可以如下定義:
livenessProbe:
httpGet:
path: /api/health
port: 80
initialDelaySeconds: 30
periodSeconds: 10
這個 livenessProbe 會在容器啟動后的30秒開始工作,每10秒檢查一次 /api/health 端點。
一個 readinessProbe 可以如下定義:
readinessProbe:
httpGet:
path: /api/ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
這個 readinessProbe 會在容器啟動后的5秒開始工作,每5秒檢查一次 /api/ready 端點。
演示
[root@kubeadm-master1 test]# cat liveness.yml
apiVersion: v1
kind: Pod
metadata:
name: my-pod1
labels:
type: app
test: "1.0.0"
namespace: default
spec:
containers:
- name: nginx
image: nginx:1.7.9
imagePullPolicy: IfNotPresent
command:
- nginx
- -g
- 'daemon off;'
workingDir: /usr/share/nginx/html
ports:
- name: http
containerPort: 80
protocol: TCP
env:
- name: JVM_OPTS
value: '-Xms128m -Xmx128m'
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 200m
memory: 256Mi
startupProbe:
httpGet:
path: /api/path
port: 80
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
livenessProbe:
httpGet:
path: /api/health
port: 80
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /api/ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
restartPolicy: OnFailure
State: Running
Started: Thu, 15 Feb 2024 15:15:19 +0800
Ready: False
Restart Count: 0
Limits:
cpu: 200m
memory: 256Mi
Requests:
cpu: 100m
memory: 128Mi
Liveness: http-get http://:80/api/health delay=30s timeout=1s period=10s #success=1 #failure=3
Readiness: http-get http://:80/api/ready delay=5s timeout=1s period=5s #success=1 #failure=3
Startup: http-get http://:80/api/path delay=0s timeout=5s period=10s #success=1 #failure=3
Environment:
JVM_OPTS: -Xms128m -Xmx128m
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-75cq9 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-75cq9:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-75cq9
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 19s default-scheduler Successfully assigned default/my-pod1 to ha2.example.local
Normal Pulled 19s kubelet Container image "nginx:1.7.9" already present on machine
Normal Created 19s kubelet Created container nginx
Normal Started 19s kubelet Started container nginx
Warning Unhealthy 2s (x2 over 12s) kubelet Startup probe failed: HTTP probe failed with statuscode: 404
若存在started.html 則進行
文章來源地址http://www.zghlxwxcb.cn/news/detail-828631.html
文章來源:http://www.zghlxwxcb.cn/news/detail-828631.html
到了這里,關(guān)于飛天使-k8s知識點17-kubernetes實操2-pod探針的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!