首页 > 其他分享 >pod资源的健康检查-readiness探针的httpGet使用

pod资源的健康检查-readiness探针的httpGet使用

时间:2022-08-23 15:57:52浏览次数:53  
标签:master1 readiness httpGet svc tanzhen pod k8s 80

livenessProbe:健康状态检查,周期性检查服务是否存活,检查结果失败,将重启容器

readinessProbe:可用性检查,周期性检查服务是否可用,不可用将从service的endpoints中移除

同一个容器中,可以同时使用livenessProbe,readinessProbe。

都是使用httpGet方式,livenessProbe探针检测容器监控状态,readinessProbe探针服务可以性

[root@k8s-master1 tanzhen]# cat nginx-deploy2-httpGet.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: readiness
spec:
  replicas: 1
  selector:
    matchLabels:
      app: readiness
      version: v1
  template:
    metadata:
     labels:
      app: readiness
      version: v1
    spec:
       containers:
       - name: readiness
         image: centos-nginx:1.23.0
         imagePullPolicy: IfNotPresent
         livenessProbe:
           httpGet:
             path: /index.html
             port: 80
           initialDelaySeconds: 5
           periodSeconds: 10
         readinessProbe:
           httpGet:           
             path: /index.html
             port: 80
           initialDelaySeconds: 5
           periodSeconds: 10

创建deployment

[root@k8s-master1 tanzhen]# kubectl apply -f nginx-deploy2-httpGet.yaml 
deployment.apps/readiness created

创建svc,

[root@k8s-master1 tanzhen]# cat svc.yaml 
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  name: readiness-svc
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: readiness
    version: v1
  type: NodePort
status:
  loadBalancer: {}
  
[root@k8s-master1 tanzhen]# kubectl apply -f svc.yaml 
service/readiness-svc created

 describe查询svc资源,可以看到Endpoints已经加入一个pod资源,如果探针检测到服务异常,就会吧对应的pod资源从Endpoints中剔除

[root@k8s-master1 tanzhen]# kubectl get svc
NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes      ClusterIP   10.96.0.1        <none>        443/TCP        10d
my-dep          NodePort    10.103.136.43    <none>        80:31644/TCP   8d
readiness-svc   NodePort    10.108.113.163   <none>        80:30663/TCP   10m
[root@k8s-master1 tanzhen]# 
[root@k8s-master1 tanzhen]# 
[root@k8s-master1 tanzhen]# kubectl describe svc readiness-svc 
Name:                     readiness-svc
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=readiness,version=v1
Type:                     NodePort
IP:                       10.108.113.163
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30663/TCP
Endpoints:                10.244.2.20:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

 

标签:master1,readiness,httpGet,svc,tanzhen,pod,k8s,80
From: https://www.cnblogs.com/xmwan/p/16615600.html

相关文章

  • HorizontalPodAutoscaler 自动扩容方式
    HorizontalPodAutoscaler(简称HPA)自动更新工作负载资源(例如 Deployment 或者 StatefulSet),目的是自动扩缩工作负载以满足需求。水平扩缩意味着对增加的负载的响应是......
  • K8s 删除Terminating状态Pod
    K8s删除Terminating状态Pod删除nfs的svc之后删除pod一直卡在Terminating状态  分析无法删除的原因在了解以上机制后,对象无法删除无外乎以下两个原因:对象存在fi......
  • 基于NFS实现pod数据持久化
    一、nfs-server服务端:挂载一块新磁盘1.1、格式化并挂载parted/dev/vdbmklablexfsparted/dev/vdbprimay0%100%mkfs.xfs/dev/vdb1 echo"/dev/vdb1/nfs_sharex......
  • Kubernetes学习笔记(十四):Static Pods
    kubelet依赖于kube-apiserver来获得关于在其node上加载哪些pod的指令,这是基于存储在etcd数据库中的kube-scheduler所做的决定。kubelet也可以独立运行,可以创建pod,可以指定......
  • 定义pod的hosts文件(HostAliases)
    通过HostAliases向Pod/etc/hosts文件添加条目当DNS配置以及其它选项不合理的时候,通过向Pod的/etc/hosts文件中添加条目,可以在Pod级别覆盖对主机名的解析。......
  • ios开发之--Cocoapods更新指定的库
    最近接手了一个swift的老项目,问题还不少,把bug修复完成功编译后,还没来得及高兴,发现一运行都崩溃,经排查是三方库太旧的原因,但是有些老版本的库又不能全部更新,所以只能更新指......
  • k8s中ingress,service,depoyment,pod如何关联
    k8s中ingress,service,depoyment,pod通过label标签名称来识别关联,它们的label name一定是一样的。1、查询发布的deploymet控制器[root@k8s-master1~]#kubectlgetdeplo......
  • podman基础命令
    podman基础命令podmancp在容器和本地文件系统之间复制文件/文件夹//将本地文件传输到容器中[root@localhost~]#podmanps-aC0ONTAINERIDIMAGECOMMANDCREATE......
  • 无根用户管理podman
    无根用户管理podman目录无根用户管理podman基础设置用户配置文件卷使用卷在允许没有root特权的用户运行Podman之前,管理员必须安装或构建Podman并完成以下配......
  • podman(无根用户管理podman)
    用户操作在允许没有root特权的用户运行Podman之前,管理员必须安装或构建Podman并完成以下配置cgroupV2Linux内核功能允许用户限制普通用户容器可以使用的资源,如果使用cgrou......