容器探测的具体实现方法;三种探针类型

ExecAction、TCPSocketAction、HTTPGetAction

  1. lifecycle <Object>
  2. Actions that the management system should take in response to container
  3. lifecycle events. Cannot be updated.
  4.  
  5. livenessProbe <Object>
  6. Periodic probe of container liveness. Container will be restarted if the
  7. probe fails. Cannot be updated. More info:
  8. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
  9. readinessProbe <Object>
  10. Periodic probe of container service readiness. Container will be removed
  11. from service endpoints if the probe fails. Cannot be updated. More info:
  12. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

  livenessProbe 介绍

  1. [root@master manifests]# kubectl explain pods.spec.containers.livenessProbe
  2. KIND: Pod
  3. VERSION: v1
  4.  
  5. RESOURCE: livenessProbe <Object>
  6.  
  7. DESCRIPTION:
  8. Periodic probe of container liveness. Container will be restarted if the
  9. probe fails. Cannot be updated. More info:
  10. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
  11.  
  12. Probe describes a health check to be performed against a container to
  13. determine whether it is alive or ready to receive traffic.
  14.  
  15. FIELDS:
  16. exec <Object> 探针
  17. One and only one of the following should be specified. Exec specifies the
  18. action to take.
  19.  
  20. failureThreshold <integer> 失败次数
  21. Minimum consecutive failures for the probe to be considered failed after
  22. having succeeded. Defaults to 3. Minimum value is 1.
  23.  
  24. httpGet <Object> http探针
  25. HTTPGet specifies the http request to perform.
  26.  
  27. initialDelaySeconds <integer> 启动后等待多长时间,开始探测
  28. Number of seconds after the container has started before liveness probes
  29. are initiated. More info:
  30. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
  31.  
  32. periodSeconds <integer> 每一次间隔时间;默认10
  33. How often (in seconds) to perform the probe. Default to 10 seconds. Minimum
  34. value is 1.
  35.  
  36. successThreshold <integer> 成功次数
  37. Minimum consecutive successes for the probe to be considered successful
  38. after having failed. Defaults to 1. Must be 1 for liveness. Minimum value
  39. is 1.
  40.  
  41. tcpSocket <Object> tcp探针
  42. TCPSocket specifies an action involving a TCP port. TCP hooks not yet
  43. supported
  44.  
  45. timeoutSeconds <integer> 每一超时时间;默认1
  46. Number of seconds after which the probe times out. Defaults to 1 second.
  47. Minimum value is 1. More info:
  48. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

  exec探测方法介绍

  1. [root@master manifests]# kubectl explain pods.spec.containers.livenessProbe.exec
  2. KIND: Pod
  3. VERSION: v1
  4.  
  5. RESOURCE: exec <Object>
  6.  
  7. DESCRIPTION:
  8. One and only one of the following should be specified. Exec specifies the
  9. action to take.
  10.  
  11. ExecAction describes a "run in container" action.
  12.  
  13. FIELDS:
  14. command <[]string> #指定运行的命令,容器里必须支持
  15. Command is the command line to execute inside the container, the working
  16. directory for the command is root ('/') in the container's filesystem. The
  17. command is simply exec'd, it is not run inside a shell, so traditional
  18. shell instructions ('|', etc) won't work. To use a shell, you need to
  19. explicitly call out to that shell. Exit status of 0 is treated as
  20. live/healthy and non-zero is unhealthy.

  编写测试

  1. [root@master manifests]# cat chenxi-exec.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: liveness-exec-pod
  6. namespace: default
  7. spec:
  8. containers:
  9. - name: liveness-exec-container
  10. image: busybox:latest
  11. imagePullPolicy: IfNotPresent
  12. command: ["/bin/sh","-c","touch /tmp/chenxi; sleep 60; rm -rf /tmp/chenxi; sleep 3600"]
  13. livenessProbe:
  14. exec:
  15. command: ["test","-e","/tmp/chenxi"]
  16. initialDelaySeconds: 2
  17. restartPolicy: OnFailure

  启动这个pod

  1. [root@master manifests]# kubectl create -f chenxi-exec.yaml
  2. pod/liveness-exec-pod created

  测试

  1. [root@master manifests]# kubectl get pods
  2. NAME READY STATUS RESTARTS AGE
  3. liveness-exec-pod 1/1 Running 0 2m
  4. myapp-84cd4b7f95-g6ldp 1/1 Running 3 10d
  5. nginx-5896f46c8-zblcs 1/1 Running 3 10d
  6. pod-demo 2/2 Running 0 162m
  7. [root@master manifests]# kubectl get pods
  8. NAME READY STATUS RESTARTS AGE
  9. liveness-exec-pod 1/1 Running 1 2m1s
  10. myapp-84cd4b7f95-g6ldp 1/1 Running 3 10d
  11. nginx-5896f46c8-zblcs 1/1 Running 3 10d
  12. pod-demo 2/2 Running 0 162m
  13. [root@master manifests]# kubectl get pods
  14. NAME READY STATUS RESTARTS AGE
  15. liveness-exec-pod 1/1 Running 1 2m2s
  16. myapp-84cd4b7f95-g6ldp 1/1 Running 3 10d
  17. nginx-5896f46c8-zblcs 1/1 Running 3 10d
  18. pod-demo 2/2 Running 0 162m

  容器创建后,终止前操作

  1. [root@master manifests]# kubectl explain pods.spec.containers.lifecycle
  2. KIND: Pod
  3. VERSION: v1
  4.  
  5. RESOURCE: lifecycle <Object>
  6.  
  7. DESCRIPTION:
  8. Actions that the management system should take in response to container
  9. lifecycle events. Cannot be updated.
  10.  
  11. Lifecycle describes actions that the management system should take in
  12. response to container lifecycle events. For the PostStart and PreStop
  13. lifecycle handlers, management of the container blocks until the action is
  14. complete, unless the container process fails, in which case the handler is
  15. aborted.
  16.  
  17. FIELDS:
  18. postStart <Object>
  19. PostStart is called immediately after a container is created. If the
  20. handler fails, the container is terminated and restarted according to its
  21. restart policy. Other management of the container blocks until the hook
  22. completes. More info:
  23. https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
  24.  
  25. preStop <Object>
  26. PreStop is called immediately before a container is terminated due to an
  27. API request or management event such as liveness probe failure, preemption,
  28. resource contention, etc. The handler is not called if the container
  29. crashes or exits. The reason for termination is passed to the handler. The
  30. Pod's termination grace period countdown begins before the PreStop hooked
  31. is executed. Regardless of the outcome of the handler, the container will
  32. eventually terminate within the Pod's termination grace period. Other
  33. management of the container blocks until the hook completes or until the
  34. termination grace period is reached. More info:
  35. https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks

  创建后操作

  1. [root@master manifests]# kubectl explain pods.spec.containers.lifecycle.postStart
  2. KIND: Pod
  3. VERSION: v1
  4.  
  5. RESOURCE: postStart <Object>
  6.  
  7. DESCRIPTION:
  8. PostStart is called immediately after a container is created. If the
  9. handler fails, the container is terminated and restarted according to its
  10. restart policy. Other management of the container blocks until the hook
  11. completes. More info:
  12. https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
  13.  
  14. Handler defines a specific action that should be taken
  15.  
  16. FIELDS:
  17. exec <Object>
  18. One and only one of the following should be specified. Exec specifies the
  19. action to take.
  20.  
  21. httpGet <Object>
  22. HTTPGet specifies the http request to perform.
  23.  
  24. tcpSocket <Object>
  25. TCPSocket specifies an action involving a TCP port. TCP hooks not yet
  26. supported

  停止前操作

  1. [root@master manifests]# kubectl explain pods.spec.containers.lifecycle.preStop
  2. KIND: Pod
  3. VERSION: v1
  4.  
  5. RESOURCE: preStop <Object>
  6.  
  7. DESCRIPTION:
  8. PreStop is called immediately before a container is terminated due to an
  9. API request or management event such as liveness probe failure, preemption,
  10. resource contention, etc. The handler is not called if the container
  11. crashes or exits. The reason for termination is passed to the handler. The
  12. Pod's termination grace period countdown begins before the PreStop hooked
  13. is executed. Regardless of the outcome of the handler, the container will
  14. eventually terminate within the Pod's termination grace period. Other
  15. management of the container blocks until the hook completes or until the
  16. termination grace period is reached. More info:
  17. https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
  18.  
  19. Handler defines a specific action that should be taken
  20.  
  21. FIELDS:
  22. exec <Object>
  23. One and only one of the following should be specified. Exec specifies the
  24. action to take.
  25.  
  26. httpGet <Object>
  27. HTTPGet specifies the http request to perform.
  28.  
  29. tcpSocket <Object>
  30. TCPSocket specifies an action involving a TCP port. TCP hooks not yet
  31. supported

  编写podyaml文件

  1. [root@master manifests]# cat pot.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: poststart-pod
  6. namespace: default
  7. spec:
  8. containers:
  9. - name: busybox-httpd
  10. image: busybox:latest
  11. imagePullPolicy: IfNotPresent
  12. lifecycle:
  13. postStart:
  14. exec:
  15. command: ['/bin/sh','-c','echo Home_Page >> /tmp/index.html']
  16. #command: ['/bin/sh','-c','sleep 3600']
  17. command: ["/bin/httpd"]
  18. args: ["-f","-h /tmp"]

  

  

k8s 的pod进阶的更多相关文章

  1. K8s的POD连接数据库时报错

    [root@cccc xxxx]# ./showlog.sh dr iff-dr-1128668949-lb90g 2017-09-29 03:21:57,575 INFO [org.wildfly. ...

  2. k8s之pod与Pod控制器

    k8s中最为重要的基础资源,pod,pod controller,service pod controller类型有多种需要向控制器赋值之后使用: kubectl命令使用 kubectk get no ...

  3. 为什么k8s引入pod概念?

    为什么k8s引入pod概念? 1.可管理性 有些容器天生需要紧密关联,以pod为最小单位进行调度 扩展 共享资源 管理生命周期 例如: 一个容器写日志,一个容器读取日志进行相关内容的展示 2.通信和资 ...

  4. k8s家族Pod辅助小能手Init容器认知答疑?

    k8s家族Pod辅助小能手Init容器认知答疑? k8s集群Init 容器是一种特殊容器,职责是在Pod的生命周期中作为应用容器的前置启动容器. 在很多应用场景中,在 Pod 内的应用容器正式启动之前 ...

  5. k8s 中 Pod 的控制器

    k8s 中 Pod 的控制器 前言 Replication Controller ReplicaSet Deployment 更新 Deployment 回滚 deployment StatefulS ...

  6. k8s之pod连接被拒排查

    k8s之pod连接被拒排查 pod链接被拒 查看pod的时候发现pod的状态为crashloopbackoff 然后看看日志发现报错如下 kubectl -n kf10 logs easydata-r ...

  7. k8s创建pod流程

    kubernetes 创建Pod 的 工作流: step.1 kubectl 向 k8s api server 发起一个create pod 请求(即我们使用Kubectl敲一个create pod命 ...

  8. K8s创建pod yaml文件详解

    kubernetes创建pod的yaml文件,参数说明 apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 ...

  9. 解决k8s出现pod服务一直处于ContainerCreating状态的问题的过程

    参考于: https://blog.csdn.net/learner198461/article/details/78036854 https://liyang.pro/solve-k8s-pod-c ...

随机推荐

  1. dfs题型一

    代码: #include <iostream> #include <algorithm> #include <vector> using namespace std ...

  2. 【资源分享】Gmod动态方框透视脚本

    *----------------------------------------------[下载区]----------------------------------------------* ...

  3. Matlab filter常用函数

    Filtering and Analysis Functions Filtering Function Description fftfilt Filters a signal with a digi ...

  4. winform学习(4)控件的添加、显示和隐藏

    窗体的添加.显示与隐藏 可以直接通过工具栏将某个控件直接拖动至UI界面(也可以在工具栏里双击某个控件) 也可以在代码里直接添加:窗体的标识.Controls.Add(控件标识符); Button my ...

  5. web布局相关

    1.用table布局时,如果设置了table-layout:fixed或者对第一行的两个列进行了合并后导致后面的列宽度失效,这是可以使用 <colgroup>        <col ...

  6. DFT 问答 III

    1.Boundary scan Boundary Scan就是我们俗称的边界扫描.Boundary Scan是上世纪90年代由 Joint Test Action Group(JTAG)提出的,它的初 ...

  7. Sql Server跨服务器操作数据

    var serversSql = "select count(*) count from sys.servers WHERE name='ITSV'"; var result = ...

  8. Docker - CentOS 7 安装

    1. 概述 安装 docker markdown 显示有点问题 代码块里的  后面应该跟一个换行, 但是没有跟 这样会导致部分命令直接执行没有反应 2. 环境 os CentOS7 用户 root 3 ...

  9. PowerDesigner--comment和name互相复制

    1.comment复制到name 脚本代码: Option Explicit ValidationMode = True InteractiveMode = im_Batch Dim mdl Set ...

  10. javaScript中的toFix(n)方法

    定义和用法 toFixed() 方法可把 Number 四舍五入为指定小数位数的数字. 语法 NumberObject.toFixed(num) 返回值 返回 NumberObject 的字符串表示, ...