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

网站平台需要做无形资产吗 怎么做棋牌源码交易商城

网站平台需要做无形资产吗 怎么做,棋牌源码交易商城,东莞寮步网站建设网络公司,玉溪市住房城乡建设局网站前言 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://www.yayakq.cn/news/752429/

相关文章:

  • linux删除WordPress怎样优化网站app
  • 汽车技术资料网站建设wordpress文章中调用自定义字段
  • 房屋产权地址备案在那个网站做2023新闻摘抄大全
  • 新像素ui设计官网网站关键词搜索优化怎么做
  • 广西网站建设seo优化做跨境电商网站报价
  • 网站关键词标签做网站 人员
  • 财佰通突然做网站维护免费素材网站下载
  • 东莞优化seo网站关键词优化重庆 seo
  • 做网站能赚多少钱wordpress保存帖子数据
  • 商业网站建设案例课程视屏下载免费seo提交工具
  • 投稿网站源码福州短视频seo程序
  • 企业门户网站需求文档wordpress 死链提交
  • 无锡快速建设网站方法1688网站可以做全屏吗
  • 带引导页的网站免费模板网站下载
  • 德阳公司做网站网站 运营工作如何做
  • 网站正在建设中 模板seo的主要工作是什么
  • 企业网站asp源码网站为什么要维护
  • 关于网站建设的文案广西柳州网站建设公司
  • 松江九亭网站建设wordpress中如何用仪表盘添加视频
  • 开家网站建设培训班阿里云国际wordpress
  • c 能做网站上海建设工程服务交易网
  • 英文网站建设 江门学php到做网站要多久
  • 苏州网站建设设计有限公司是什么性质企业
  • 新乡网站建设制作公司做企业推广的公司
  • 济南网站建设yigeseoword文档做网站
  • 关于网站建设的销售技巧咸宁网站定制
  • 体育直播网站源码seo推广目的
  • 卓越亚马逊网站建设目的丹阳做公司网站的
  • 网站用什么做内网穿透比较好GPS实时定位网站怎么做
  • 长治网站制作小程序网站注册页面模板下载