资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Pod存活性探测

  Pod存活性探测:用于判断容器是否处理"运行"状态,如果检测未通过,kubelet将会终止容器,根据启动策略(restartPolicy)决定是否重启,如果未定义容器默认为"Success"。存活性探测支持的方法有三种:ExecAction,TCPSocketAction,HTTPGetAction。

创新互联长期为上千多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为塔河企业提供专业的网站设计、成都做网站,塔河网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。

1.使用exec探测文件存在

[root@k8s01 yaml]# kubectl explain pods.spec.containers.livenessProbe

[root@k8s01 yaml]# vim execaction.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: exec-execaction
  name: execaction
spec:
  containers:
  - name: execaction
    image: busybox:latest
    args: ["/bin/sh","-c","touch /tmp/test.txt"]        --容器启动后创建test.txt文件
    livenessProbe:
      exec:
        command: ["test","-e","/tmp/test.txt"]      --检查test.txt文件,如果存在Pod正常启动,如果不存在Pod创建不成功

[root@k8s01 yaml]# kubectl apply -f execaction.yaml

pod/execaction created

[root@k8s01 yaml]#

2.使用tcp协议探测端口

[root@k8s01 yaml]# vim tcpaction.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: tcp-execaction
  name: tcpaction
spec:
  containers:
  - name: tcpaction
    image: nginx:latest
    ports:
    - name: http
      containerPort: 80    --暴露80端口
    livenessProbe:   
      tcpSocket:      --使用tcp探测
        port: http    --这里可以写协议或者端口,http默认为80端口

[root@k8s01 yaml]# kubectl apply -f  tcpaction.yaml
pod/tcpaction created
[root@k8s01 yaml]#

3.使用http协议探测服务

[root@k8s01 yaml]# vim httpaction.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: http-execaction
  name: httpaction
spec:
  containers:
  - name: httpaction
    image: nginx:latest
    ports:
    - name: http
      containerPort: 80
    lifecycle:
      postStart:     --容器启动之前启动以下命令
        exec:
          command: ["/bin/sh","-c","echo 123 > /usr/share/nginx/html/test.html"]
    livenessProbe:
      httpGet:
        path: /test.html    --探测nginx是否正常访问test.html页面
        port: http

[root@k8s01 yaml]# kubectl  apply -f httpaction.yaml
pod/httpaction created
[root@k8s01 yaml]#


本文标题:Pod存活性探测
文章网址:http://cdkjz.cn/article/jhhsso.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220