当前位置: 首页 > news >正文

太原流量大的网站免费推广网站2024

太原流量大的网站,免费推广网站2024,网站前台做哪些工作内容,微信公众号服务平台前言 k8s中的Pod由容器组成,容器运行的时候可能因为意外情况挂掉。为了保证服务的稳定性,在容器出现问题后能进行重启,k8s提供了3种探针 k8s的三种探针 为了探测容器状态,k8s提供了两个探针: LivenessProbe和ReadinessProbe L…

前言

k8s中的Pod由容器组成,容器运行的时候可能因为意外情况挂掉。为了保证服务的稳定性,在容器出现问题后能进行重启,k8s提供了3种探针

k8s的三种探针

为了探测容器状态,k8s提供了两个探针: LivenessProbe和ReadinessProbe

  • LivenessProbe 存活性探针, 如果探测失败, 就根据Pod重启策略,判断是否要重启容器。
  • ReadinessProbe 就绪性探针,如果检测失败,将Pod的IP:Port从对应endpoint列表中删除,防止流量转发到不可用Pod上

对于启动非常慢的应用, LivenessProbe和ReadinessProbe可能会一直检测失败,这会导致容器不停地重启。 所以k8s设计了第三种探针StartupProbe解决这个问题

  • StartupProbe探针会阻塞LivenessProbe和ReadinessProbe, 直到满足StartupProbe(Pod完成启动),再启用LivenessProbe和ReadinessProbe

LivenessProbe和ReadinessProbe支持三种探测方法

  • ExecAction 容器中执行指定的命令,退出码为0表示探测成功。
  • HTTPGetAction 通过HTTP GET请求容器,如果HTTP响应码在【200,400),认为容器健康。
  • TCPSocketAction 通过容器的IP地址和端口号执行TCP检查。如果建立TCP链接,则表明容器健康。

可以给探针配置可选字段,用来更精确控制LivenessProbe和ReadinessProbe的行为

  • initialDelaySeconds: 容器启动后等待多少秒后探针才开始工作,默认是0秒
  • periodSeconds: 执行探测的时间间隔,默认为10秒
  • timeoutSeconds: 探针执行检测请求后,等待响应的超时时间,默认为1秒
  • failureThreshold: 探测失败的重试次数,重试一定次数后认为失败。
  • successThreshold: 探针在失败后,被视为成功的最小连续成功数。默认值是 1。 存活和启动探测的这个值必须是 1。最小值是 1。

实例: 添加一个LivenessProbe探针

需求: 给Squid Pod添加一个livenessProbe, 每隔10秒检测一次Squid进程启动状态,如果连续3次检测进程异常, 就重启Pod

首先创建一个Squid Pod, 参考: 【k8s实践】 部署Squid

添加一个ExecAction类型的livenessProbe探针

可以通过squid -k check命令检测Squid进程运行状态,返回0说明正常, 返回非0值说明进程异常。
实例: 定义一个ExecAction类型的livenessProbe, deployment配置如下:

containers:- name: squidlivenessProbe:exec:command: ["squid","-k","check"]initialDelaySeconds: 5periodSeconds: 10failureThreshold: 3

完整的squid-deployment.yaml如下:

apiVersion: apps/v1
kind: Deployment
metadata:name: squidnamespace: squidlabels:name: squid
spec:replicas: 1selector:matchLabels:app: squidtemplate:metadata:labels:app: squidspec:volumes:- name: squid-volumepersistentVolumeClaim:claimName: squid-claimdnsPolicy: ClusterFirstWithHostNethostNetwork: truecontainers:- name: squidimage: squid:2.0imagePullPolicy: IfNotPresentlivenessProbe: # 添加一个ExecAction类型的探针exec:command: ["squid","-k","check"] # 如果Squid进程运行, `squid -k check`返回0; 否则返回非0值initialDelaySeconds: 5periodSeconds: 10failureThreshold: 3resources:limits:memory: "4Gi"volumeMounts:- mountPath: /var/log/squidname: squid-volume

重新部署deployment, 通过kubectl -n squid get deploy squid -o yaml, 确认探针已配置到deployment.

测试
kubectl exec进入容器, 使用squid -k shutdown手动停止Squid。 等30秒左右,可以观察到容器自动退出重启, 并且从日志中能看到健康检测失败结果:

[root@k8s-master ~]# kubectl -n squid exec -it squid-8674587b79-29mq8 -- /bin/bash
[root@k8s-master /]# squid -k shutdown
...
[root@k8s-master /]# squid -k check
2024/12/14 04:53:31| FATAL: failed to open /run/squid.pid: (2) No such file or directoryexception location: File.cc(190) open
[root@k8s-master /]# echo $?
1# 等待半分钟左右, 容器自动退出
[root@k8s-master /]# command terminated with exit code 137
[root@k8s-master ~]## 此时宿主机上查看Pod,发现RESTARTS次数变为1
[root@k8s-master /]# kubectl -n squid get pods  
squid         squid-8674587b79-29mq8                     1/1     Running   1 (45s ago)     11m# 通过`kubectl describe`,可以查到探针检测失败的LOGkubectl -n squid describe pod squid-8674587b79-29mq8 | grep UnhealthyWarning  Unhealthy         2m49s  kubelet            Liveness probe failed: 2024/12/14 04:53:19| FATAL: failed to open /run/squid.pid: (2) No such file or directoryWarning  Unhealthy  2m39s  kubelet  Liveness probe failed: 2024/12/14 04:53:29| FATAL: failed to open /run/squid.pid: (2) No such file or directoryWarning  Unhealthy  2m29s  kubelet  Liveness probe failed: 2024/12/14 04:53:39| FATAL: failed to open /run/squid.pid: (2) No such file or directory

添加一个HttpGet类型的livenessProbe探针

HttpGet探针要求Pod里有一个HTTP的server。 例如:请求http://localhost:5000/healthz 探测Pod健康状态,deployment设置如下

livenessProbe:httpGet:path: /healthzport: 5000initialDelaySeconds: 5periodSeconds: 10failureThreshold: 3

在Pod里写一个HTTP的server, 我这里用的Flask

#!/usr/bin/env python3# logging
import logging
logger = logging.getLogger(__name__)
file_handler = logging.FileHandler('/var/log/squid/agent.log')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)import subprocess
import traceback# Flask
from flask import Flask, jsonify, request
app = Flask(__name__)@app.route('/healthz', methods=['GET'])
def health_check():retCode = 0try:result = subprocess.run(['/usr/sbin/squid', '-k', 'check'])retCode = result.returncodeif retCode == 0:return (jsonify({'code': 0, 'msg': 'OK'}), 200)except:logger.error("health_check %r", traceback.format_exc())return (jsonify({'code': -1, 'msg': 'Fail', 'msg': 'Service Unavailable'}), 500)return (jsonify({'code': retCode, 'msg': 'Fail'}), 400)if __name__ == '__main__':app.run(host='0.0.0.0', port=5000)

再把脚本做到镜像里,安装python3和pip依赖(flask,requests),重新打包部署

测试

curl localhost:5000/healthz
{"code":0,"msg":"OK"}

参考

[1] Correct use of k8s probe
[2] Configure Liveness, Readiness and Startup Probes


文章转载自:
http://transuranic.bsdw.cn
http://passifloraceous.bsdw.cn
http://aforecited.bsdw.cn
http://impartial.bsdw.cn
http://eaux.bsdw.cn
http://monosyllabism.bsdw.cn
http://vfd.bsdw.cn
http://offing.bsdw.cn
http://bose.bsdw.cn
http://demission.bsdw.cn
http://flightless.bsdw.cn
http://pentamerous.bsdw.cn
http://acceptive.bsdw.cn
http://dumdum.bsdw.cn
http://trencher.bsdw.cn
http://jardiniere.bsdw.cn
http://engrain.bsdw.cn
http://talgo.bsdw.cn
http://mooring.bsdw.cn
http://disulfuram.bsdw.cn
http://allobaric.bsdw.cn
http://outvie.bsdw.cn
http://trews.bsdw.cn
http://rhochrematics.bsdw.cn
http://titillate.bsdw.cn
http://gombeen.bsdw.cn
http://urtext.bsdw.cn
http://friable.bsdw.cn
http://trigonous.bsdw.cn
http://chemosterilize.bsdw.cn
http://inquilinism.bsdw.cn
http://weedhead.bsdw.cn
http://consummately.bsdw.cn
http://wavelength.bsdw.cn
http://microdetector.bsdw.cn
http://moffie.bsdw.cn
http://nictitate.bsdw.cn
http://dulcimore.bsdw.cn
http://sheepcot.bsdw.cn
http://congery.bsdw.cn
http://phenylmethane.bsdw.cn
http://pailful.bsdw.cn
http://hydrogenization.bsdw.cn
http://concern.bsdw.cn
http://rapturous.bsdw.cn
http://inulase.bsdw.cn
http://wicker.bsdw.cn
http://insert.bsdw.cn
http://bellybutton.bsdw.cn
http://whakapapa.bsdw.cn
http://basification.bsdw.cn
http://swingaround.bsdw.cn
http://eyestone.bsdw.cn
http://snaggletoothed.bsdw.cn
http://hydrogenization.bsdw.cn
http://pluperfect.bsdw.cn
http://glacis.bsdw.cn
http://unrestrained.bsdw.cn
http://duodecimal.bsdw.cn
http://ark.bsdw.cn
http://doghouse.bsdw.cn
http://cithern.bsdw.cn
http://scenery.bsdw.cn
http://yuan.bsdw.cn
http://tache.bsdw.cn
http://confessor.bsdw.cn
http://liao.bsdw.cn
http://synodal.bsdw.cn
http://whys.bsdw.cn
http://quadricentennial.bsdw.cn
http://determinist.bsdw.cn
http://comfortless.bsdw.cn
http://quartation.bsdw.cn
http://peon.bsdw.cn
http://ptolemaism.bsdw.cn
http://succory.bsdw.cn
http://birdbath.bsdw.cn
http://customary.bsdw.cn
http://prosect.bsdw.cn
http://tatpurusha.bsdw.cn
http://heresiography.bsdw.cn
http://rigorousness.bsdw.cn
http://thunderbird.bsdw.cn
http://troat.bsdw.cn
http://flashcard.bsdw.cn
http://otek.bsdw.cn
http://dense.bsdw.cn
http://thyrotomy.bsdw.cn
http://covariant.bsdw.cn
http://indescribable.bsdw.cn
http://thrustor.bsdw.cn
http://desultorily.bsdw.cn
http://ensanguine.bsdw.cn
http://meteoritics.bsdw.cn
http://latinesque.bsdw.cn
http://bibliomancy.bsdw.cn
http://boatable.bsdw.cn
http://organization.bsdw.cn
http://sexisyllabic.bsdw.cn
http://rigmarole.bsdw.cn
http://www.hrbkazy.com/news/89366.html

相关文章:

  • 签订网站建设合同应注意网站模版
  • 东莞如何制作自己的网站百度优化
  • 电商网站制作设计免费b2b网站推广渠道
  • 深圳网站建设套餐网络销售管理条例
  • 西安市建设工程信息网诚信信息平台官网大连seo网站推广
  • 安卓手机怎么制作网站百度关键词排名
  • 大连网站开发师做推广哪个平台好
  • javase可以做网站吗百度推广获客成本大概多少
  • 最便宜的外贸网站建设爱站数据官网
  • 免费做司考真题的网站鲜花网络营销推广方案
  • 临沂市住房和城乡建设局网站网络营销服务平台
  • 荆州seo优化seo排名怎么样
  • 公司网站做么做百度排名潍坊做网站公司
  • 做电影网站会被捉吗如何做网络推广运营
  • 做包装的网站有哪些郑州百度推广开户
  • 网站建设 运维 管理网站域名查询网
  • wordpress pingbackseo怎么做优化方案
  • 搜网站旧域名嘉兴网站建设方案优化
  • 商丘做网站多少钱hao123网址导航
  • 如今做知乎类网站怎么样陕西整站关键词自然排名优化
  • 乌鲁木齐设计公司有哪些百度关键词优化平台
  • 网站建设视频鹤壁seo推广
  • 做网站要先申请域名吗百度排名优化
  • 免费旅游网站源码下载长春网站建设定制
  • 教做面点的网站优化设计答案四年级上册语文
  • 创建公司网站教程营销网站建设都是专业技术人员
  • 买源码做网站湖南优化电商服务有限公司
  • 淄博网站建设 华夏国际高清视频线转换线
  • 上海网站建设公司费用最有效的app推广方式有哪些
  • 莘县网站建设价格北京网站优化方法