k8s 的pod进阶
容器探测的具体实现方法;三种探针类型
ExecAction、TCPSocketAction、HTTPGetAction
lifecycle <Object>
Actions that the management system should take in response to container
lifecycle events. Cannot be updated. livenessProbe <Object>
Periodic probe of container liveness. Container will be restarted if the
probe fails. Cannot be updated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
readinessProbe <Object>
Periodic probe of container service readiness. Container will be removed
from service endpoints if the probe fails. Cannot be updated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
livenessProbe 介绍
[root@master manifests]# kubectl explain pods.spec.containers.livenessProbe
KIND: Pod
VERSION: v1 RESOURCE: livenessProbe <Object> DESCRIPTION:
Periodic probe of container liveness. Container will be restarted if the
probe fails. Cannot be updated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes Probe describes a health check to be performed against a container to
determine whether it is alive or ready to receive traffic. FIELDS:
exec <Object> 探针
One and only one of the following should be specified. Exec specifies the
action to take. failureThreshold <integer> 失败次数
Minimum consecutive failures for the probe to be considered failed after
having succeeded. Defaults to 3. Minimum value is 1. httpGet <Object> http探针
HTTPGet specifies the http request to perform. initialDelaySeconds <integer> 启动后等待多长时间,开始探测
Number of seconds after the container has started before liveness probes
are initiated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes periodSeconds <integer> 每一次间隔时间;默认10秒
How often (in seconds) to perform the probe. Default to 10 seconds. Minimum
value is 1. successThreshold <integer> 成功次数
Minimum consecutive successes for the probe to be considered successful
after having failed. Defaults to 1. Must be 1 for liveness. Minimum value
is 1. tcpSocket <Object> tcp探针
TCPSocket specifies an action involving a TCP port. TCP hooks not yet
supported timeoutSeconds <integer> 每一超时时间;默认1秒
Number of seconds after which the probe times out. Defaults to 1 second.
Minimum value is 1. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
exec探测方法介绍
[root@master manifests]# kubectl explain pods.spec.containers.livenessProbe.exec
KIND: Pod
VERSION: v1 RESOURCE: exec <Object> DESCRIPTION:
One and only one of the following should be specified. Exec specifies the
action to take. ExecAction describes a "run in container" action. FIELDS:
command <[]string> #指定运行的命令,容器里必须支持
Command is the command line to execute inside the container, the working
directory for the command is root ('/') in the container's filesystem. The
command is simply exec'd, it is not run inside a shell, so traditional
shell instructions ('|', etc) won't work. To use a shell, you need to
explicitly call out to that shell. Exit status of 0 is treated as
live/healthy and non-zero is unhealthy.
编写测试
[root@master manifests]# cat chenxi-exec.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec-pod
namespace: default
spec:
containers:
- name: liveness-exec-container
image: busybox:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","touch /tmp/chenxi; sleep 60; rm -rf /tmp/chenxi; sleep 3600"]
livenessProbe:
exec:
command: ["test","-e","/tmp/chenxi"]
initialDelaySeconds: 2
restartPolicy: OnFailure
启动这个pod
[root@master manifests]# kubectl create -f chenxi-exec.yaml
pod/liveness-exec-pod created
测试
[root@master manifests]# kubectl get pods
NAME READY STATUS RESTARTS AGE
liveness-exec-pod 1/1 Running 0 2m
myapp-84cd4b7f95-g6ldp 1/1 Running 3 10d
nginx-5896f46c8-zblcs 1/1 Running 3 10d
pod-demo 2/2 Running 0 162m
[root@master manifests]# kubectl get pods
NAME READY STATUS RESTARTS AGE
liveness-exec-pod 1/1 Running 1 2m1s
myapp-84cd4b7f95-g6ldp 1/1 Running 3 10d
nginx-5896f46c8-zblcs 1/1 Running 3 10d
pod-demo 2/2 Running 0 162m
[root@master manifests]# kubectl get pods
NAME READY STATUS RESTARTS AGE
liveness-exec-pod 1/1 Running 1 2m2s
myapp-84cd4b7f95-g6ldp 1/1 Running 3 10d
nginx-5896f46c8-zblcs 1/1 Running 3 10d
pod-demo 2/2 Running 0 162m
容器创建后,终止前操作
[root@master manifests]# kubectl explain pods.spec.containers.lifecycle
KIND: Pod
VERSION: v1 RESOURCE: lifecycle <Object> DESCRIPTION:
Actions that the management system should take in response to container
lifecycle events. Cannot be updated. Lifecycle describes actions that the management system should take in
response to container lifecycle events. For the PostStart and PreStop
lifecycle handlers, management of the container blocks until the action is
complete, unless the container process fails, in which case the handler is
aborted. FIELDS:
postStart <Object>
PostStart is called immediately after a container is created. If the
handler fails, the container is terminated and restarted according to its
restart policy. Other management of the container blocks until the hook
completes. More info:
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks preStop <Object>
PreStop is called immediately before a container is terminated due to an
API request or management event such as liveness probe failure, preemption,
resource contention, etc. The handler is not called if the container
crashes or exits. The reason for termination is passed to the handler. The
Pod's termination grace period countdown begins before the PreStop hooked
is executed. Regardless of the outcome of the handler, the container will
eventually terminate within the Pod's termination grace period. Other
management of the container blocks until the hook completes or until the
termination grace period is reached. More info:
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
创建后操作
[root@master manifests]# kubectl explain pods.spec.containers.lifecycle.postStart
KIND: Pod
VERSION: v1 RESOURCE: postStart <Object> DESCRIPTION:
PostStart is called immediately after a container is created. If the
handler fails, the container is terminated and restarted according to its
restart policy. Other management of the container blocks until the hook
completes. More info:
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks Handler defines a specific action that should be taken FIELDS:
exec <Object>
One and only one of the following should be specified. Exec specifies the
action to take. httpGet <Object>
HTTPGet specifies the http request to perform. tcpSocket <Object>
TCPSocket specifies an action involving a TCP port. TCP hooks not yet
supported
停止前操作
[root@master manifests]# kubectl explain pods.spec.containers.lifecycle.preStop
KIND: Pod
VERSION: v1 RESOURCE: preStop <Object> DESCRIPTION:
PreStop is called immediately before a container is terminated due to an
API request or management event such as liveness probe failure, preemption,
resource contention, etc. The handler is not called if the container
crashes or exits. The reason for termination is passed to the handler. The
Pod's termination grace period countdown begins before the PreStop hooked
is executed. Regardless of the outcome of the handler, the container will
eventually terminate within the Pod's termination grace period. Other
management of the container blocks until the hook completes or until the
termination grace period is reached. More info:
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks Handler defines a specific action that should be taken FIELDS:
exec <Object>
One and only one of the following should be specified. Exec specifies the
action to take. httpGet <Object>
HTTPGet specifies the http request to perform. tcpSocket <Object>
TCPSocket specifies an action involving a TCP port. TCP hooks not yet
supported
编写podyaml文件
[root@master manifests]# cat pot.yaml
apiVersion: v1
kind: Pod
metadata:
name: poststart-pod
namespace: default
spec:
containers:
- name: busybox-httpd
image: busybox:latest
imagePullPolicy: IfNotPresent
lifecycle:
postStart:
exec:
command: ['/bin/sh','-c','echo Home_Page >> /tmp/index.html']
#command: ['/bin/sh','-c','sleep 3600']
command: ["/bin/httpd"]
args: ["-f","-h /tmp"]
k8s 的pod进阶的更多相关文章
- K8s的POD连接数据库时报错
[root@cccc xxxx]# ./showlog.sh dr iff-dr-1128668949-lb90g 2017-09-29 03:21:57,575 INFO [org.wildfly. ...
- k8s之pod与Pod控制器
k8s中最为重要的基础资源,pod,pod controller,service pod controller类型有多种需要向控制器赋值之后使用: kubectl命令使用 kubectk get no ...
- 为什么k8s引入pod概念?
为什么k8s引入pod概念? 1.可管理性 有些容器天生需要紧密关联,以pod为最小单位进行调度 扩展 共享资源 管理生命周期 例如: 一个容器写日志,一个容器读取日志进行相关内容的展示 2.通信和资 ...
- k8s家族Pod辅助小能手Init容器认知答疑?
k8s家族Pod辅助小能手Init容器认知答疑? k8s集群Init 容器是一种特殊容器,职责是在Pod的生命周期中作为应用容器的前置启动容器. 在很多应用场景中,在 Pod 内的应用容器正式启动之前 ...
- k8s 中 Pod 的控制器
k8s 中 Pod 的控制器 前言 Replication Controller ReplicaSet Deployment 更新 Deployment 回滚 deployment StatefulS ...
- k8s之pod连接被拒排查
k8s之pod连接被拒排查 pod链接被拒 查看pod的时候发现pod的状态为crashloopbackoff 然后看看日志发现报错如下 kubectl -n kf10 logs easydata-r ...
- k8s创建pod流程
kubernetes 创建Pod 的 工作流: step.1 kubectl 向 k8s api server 发起一个create pod 请求(即我们使用Kubectl敲一个create pod命 ...
- K8s创建pod yaml文件详解
kubernetes创建pod的yaml文件,参数说明 apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 ...
- 解决k8s出现pod服务一直处于ContainerCreating状态的问题的过程
参考于: https://blog.csdn.net/learner198461/article/details/78036854 https://liyang.pro/solve-k8s-pod-c ...
随机推荐
- Vue的响应式原理---(v-model中的双向绑定原理)
Vue响应式原理 不要认为数据发生改变,界面跟着更新是理所当然. 具体代码实现:https://gitee.com/ahaMOMO/Vue-Responsive-Principle.git 看下图: ...
- Module build failed: TypeError: this.getResolve is not a function at Object.loader sass报错!(亲测有效!~~)
vue安装node-sass编译报错 在搭建vue脚手架 或者是在vue项目中,想使用sass的功能,需先安装如下 npm install node-sass --save-dev //安装node- ...
- KMP字符串匹配算法详解
KMP算法利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的.具体实现就是实现一个next()函数,函数本身包含了模式串的局部匹配信息.时间复杂度O(m+n). Next()函数 ...
- WSAGetLastError错误原因的博客与时间函数
https://blog.csdn.net/skc361/article/details/9254507 https://blog.csdn.net/HK_5788/article/details/4 ...
- zookeeper and kafka
kafka安装前期准备: 1,准备三个节点(根据自己需求决定) 2,三个节点上安装好zookeeper(也可以使用kafka自带的zookeeper) 3,关闭防火墙 chkconfig iptab ...
- Codeforces Round #618 (Div. 1)A(观察规律)
实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...
- 作业1:使用go搭建一个web-server
todo1:搭建web-server的原理 todo2:go实现web-server
- 大组合数Lucas
https://blog.csdn.net/sr_19930829/article/details/39058487 LL Lucas(LL n, LL m, int p){ ; } Saving B ...
- Bugku-CTF加密篇之凯撒部长的奖励(就在8月,超师傅出色地完成了上级的特遣任务,凯撒部长准备给超师傅一份特殊的奖励.......)
凯撒部长的奖励 就在8月,超师傅出色地完成了上级的特遣任务,凯撒部长准备给超师傅一份特殊的奖励,兴高采烈的超师傅却只收到一长串莫名的密文,超师傅看到英语字串便满脸黑线,帮他拿到这份价值不菲的奖励吧. ...
- 【转】 WordPress数据库及各表结构分析
默认WordPress一共有以下11个表.这里加上了默认的表前缀 wp_ . wp_commentmeta:存储评论的元数据wp_comments:存储评论wp_links:存储友情链接(Blogro ...