侧边栏壁纸
博主头像
码途 博主等级

行动起来,活在当下

  • 累计撰写 72 篇文章
  • 累计创建 0 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录
k8s

配置健康检查 - k8s

htmltoo
2023-12-14 / 0 评论 / 0 点赞 / 4 阅读 / 0 字

重启策略

Always: 当容器终止后,总是重启,默认策略

OnFailure: 当容器异常退出(退出状态码非0)时,才重启容器

Never: 不论容器状态如何,都不重启容器

3种检查方式

httpGet: 发送HTTP请求,返回200-400范围状态码表示成功

exec: 执行Shell命令返回状态码为0表示成功

tcpSocket: 发起TCP Socket建立成功

initialDelaySeconds: 第一次启动Pod后等待多久时间开始健康检查

failureThreshold: 探针执行失败几次后容器状态变为失败,默认3次

periodSeconds: 健康检查的周期

完整yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: web
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      restartPolicy: Always
      containers:
      - image: nginx
        imagePullPolicy: IfNotPresent
        name: web
        ports:
        - containerPort: 80
        livenessProbe:
          tcpSocket:
            port: 80
          initialDelaySeconds: 5
          failureThreshold: 2
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /index.html
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
        startupProbe:  # startupProbe
	      httpGet:
	        path: /healthz
	        port: liveness-port
	      failureThreshold: 30
	      periodSeconds: 10  # 容器启动30*10=300s内liveness和readiness探针不会执行,300s后startup探针还没成功,容器会被kill掉重启

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: web
  name: web
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    app: web
  type: NodePort

0

评论区