摘要:记录一个简单的的使用创建探针具体的文件如下创建该查看当前的状态测试将容器内的删除掉登陆容器使用命令登陆容器可以看到,当我们把移走后,这个容器立马就退出了。
记录一个简单的livenessProb的使用
创建livenessProbe探针具体的liveness-httpget.yaml文件如下:
apiVersion: v1 kind: Pod metadata: name: liveness-httpget-pod namespace: default spec: containers: - name: liveness-exec-container image: ikubernetes/myapp:v1 imagePullPolicy: IfNotPresent ports: - name: http containerPort: 80 livenessProbe: httpGet: port: http path: /index.html initialDelaySeconds: 1 periodSeconds: 3 [root@master manifests]# cat liveness-httpget.yaml apiVersion: v1 kind: Pod metadata: name: liveness-httpget-pod namespace: default spec: containers: - name: liveness-exec-container image: ikubernetes/myapp:v1 imagePullPolicy: IfNotPresent ports: - name: http containerPort: 80 livenessProbe: httpGet: port: http path: /index.html initialDelaySeconds: 1 periodSeconds: 3
创建该pod
[root@master manifests]# kubectl create -f liveness-httpget.yaml pod/liveness-httpget-pod created
查看当前pod的状态
[root@master manifests]# kubectl describe pod liveness-httpget-pod Name: liveness-httpget-pod Namespace: default Priority: 0 PriorityClassName:测试将容器内的index.html删除掉 登陆容器Node: node02/192.168.18.130 Start Time: Fri, 17 Aug 2018 18:24:26 +0800 Labels: Annotations: Status: Running IP: 10.244.2.40 Containers: liveness-exec-container: Container ID: docker://b00bc09eac7c4dcadb482dd9795a9f7e6d9b68ca63e75384da18feb0ef7bdc6d Image: ikubernetes/myapp:v1 Image ID: docker-pullable://ikubernetes/myapp@sha256:9c3dc30b5219788b2b8a4b065f548b922a34479577befb54b03330999d30d513 Port: 80/TCP Host Port: 0/TCP State: Running Started: Fri, 17 Aug 2018 18:24:27 +0800 Ready: True Restart Count: 0 Liveness: http-get http://:http/index.html delay=1s timeout=1s period=3s #success=1 #failure=3 Environment: Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-qcfxf (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: default-token-qcfxf: Type: Secret (a volume populated by a Secret) SecretName: default-token-qcfxf Optional: false QoS Class: BestEffort Node-Selectors: Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Pulled 37s kubelet, node02 Container image "ikubernetes/myapp:v1" already present on machine Normal Created 37s kubelet, node02 Created container Normal Started 37s kubelet, node02 Started container Normal Scheduled 32s default-scheduler Successfully assigned default/liveness-httpget-pod to node02
使用命令 kubectl exec liveness-httpget-pod -c liveness-exec-container -it -- /bin/sh 登陆容器
[root@master manifests]# kubectl exec liveness-httpget-pod -c liveness-exec-container -it -- /bin/sh / # ls bin dev etc home lib media mnt proc root run sbin srv sys tmp usr var / # mv /usr/share/nginx/html/index.html index.html / # command terminated with exit code 137
可以看到,当我们把index.html移走后,这个容器立马就退出了。
此时,查看pod的信息
[root@master manifests]# kubectl describe pod liveness-httpget-pod Name: liveness-httpget-pod Namespace: default Priority: 0 PriorityClassName:Node: node02/192.168.18.130 Start Time: Fri, 17 Aug 2018 18:24:26 +0800 Labels: Annotations: Status: Running IP: 10.244.2.40 Containers: liveness-exec-container: Container ID: docker://ac663b9e29c2cbc9c1d0283f1609914be69964149247945266ddcc8b33dde12f Image: ikubernetes/myapp:v1 Image ID: docker-pullable://ikubernetes/myapp@sha256:9c3dc30b5219788b2b8a4b065f548b922a34479577befb54b03330999d30d513 Port: 80/TCP Host Port: 0/TCP State: Running Started: Fri, 17 Aug 2018 18:48:07 +0800 Last State: Terminated Reason: Completed Exit Code: 0 Started: Fri, 17 Aug 2018 18:24:27 +0800 Finished: Fri, 17 Aug 2018 18:48:06 +0800 Ready: True Restart Count: 1 Liveness: http-get http://:http/index.html delay=1s timeout=1s period=3s #success=1 #failure=3 Environment: Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-qcfxf (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: default-token-qcfxf: Type: Secret (a volume populated by a Secret) SecretName: default-token-qcfxf Optional: false QoS Class: BestEffort Node-Selectors: Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 24m default-scheduler Successfully assigned default/liveness-httpget-pod to node02 Warning Unhealthy 1m (x3 over 1m) kubelet, node02 Liveness probe failed: HTTP probe failed with statuscode: 404 Normal Pulled 1m (x2 over 24m) kubelet, node02 Container image "ikubernetes/myapp:v1" already present on machine Normal Created 1m (x2 over 24m) kubelet, node02 Created container Normal Started 1m (x2 over 24m) kubelet, node02 Started container Normal Killing 1m kubelet, node02 Killing container with id docker://liveness-exec-container:Container failed liveness probe.. Container will be killed and recreated.
看输出,容器由于健康检查未通过,pod会被杀掉,并重新创建
[root@master manifests]# kubectl get pods NAME READY STATUS RESTARTS AGE liveness-httpget-pod 1/1 Running 1 33m
restarts 为 1
重新登陆容器查看重新登陆容器,发现index.html又出现了,证明容器是被重拉了。
[root@master manifests]# kubectl exec liveness-httpget-pod -c liveness-exec-container -it -- /bin/sh / # cat /usr/share/nginx/html/index.html Hello MyApp | Version: v1 | Pod Name
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/32699.html
摘要:配置配置使用概率抽样。采样率定义了对跟踪跨度进行采样的概率,其值可以介于和含之间。例如,以下配置对象将采样率更改为即每个跨度都被采样,并使用协议将跟踪发送到位于的服务器文件路径注将采样率更改为会完全禁用跟踪。目录手把手教你学Dapr - 1. .Net开发者的大时代手把手教你学Dapr - 2. 必须知道的概念手把手教你学Dapr - 3. 使用Dapr运行第一个.Net程序手把手教你学Da...
摘要:常用命令服务启动滚动升级概念集群分布式存储保存了整个集群的状态控制节点控制节点负责整个集群的管理,例如容器调度资源状态维护自动扩展滚动更新等服务节点服务节点是真正运行容器 1.常用命令 服务启动 [root@k8s-master ~]# systemctl start etcd [root@k8s-master ~]# systemctl start docker [root@k8s-...
摘要:在本文中,我们将讨论,一种本地健康检查应用程序的方法。标准的健康检查工具,可以轻松查询健康协议。选择二进制版本并将其下载到中在你的中指定容器的。服务器健康检查的代码实现,主要部分如下完整代码,请查看仓库。 前言 GRPC正在成为云原生微服务之间通信的通用语言。如果您今天要将gRPC应用程序部署到Kubernetes,您可能想知道配置运行状况检查的最佳方法。在本文中,我们将讨论grpc-...
摘要:在本文中,我们将讨论,一种本地健康检查应用程序的方法。标准的健康检查工具,可以轻松查询健康协议。选择二进制版本并将其下载到中在你的中指定容器的。服务器健康检查的代码实现,主要部分如下完整代码,请查看仓库。 前言 GRPC正在成为云原生微服务之间通信的通用语言。如果您今天要将gRPC应用程序部署到Kubernetes,您可能想知道配置运行状况检查的最佳方法。在本文中,我们将讨论grpc-...
摘要:在本文中,我们将讨论,一种本地健康检查应用程序的方法。标准的健康检查工具,可以轻松查询健康协议。选择二进制版本并将其下载到中在你的中指定容器的。服务器健康检查的代码实现,主要部分如下完整代码,请查看仓库。 前言 GRPC正在成为云原生微服务之间通信的通用语言。如果您今天要将gRPC应用程序部署到Kubernetes,您可能想知道配置运行状况检查的最佳方法。在本文中,我们将讨论grpc-...
阅读 2361·2021-11-18 10:02
阅读 657·2021-10-08 10:04
阅读 2201·2021-09-03 10:51
阅读 3505·2019-08-30 15:44
阅读 2753·2019-08-29 14:09
阅读 2433·2019-08-29 12:21
阅读 2036·2019-08-26 13:45
阅读 1767·2019-08-26 13:25