首页 > 其他分享 >pod探针和重启策略

pod探针和重启策略

时间:2023-03-08 12:00:11浏览次数:41  
标签:name 80 探针 app redis nginx pod 重启

示例:livenessProbe和HTTPGetAction:
[root@localhost7C ~]#cat nginx-http.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-linux39
  template:
    metadata:
      labels:
        app: nginx-linux39
    spec:
      containers:
      - name: nginx
        image: harbor.linux39.com/baseimages/nginx:1.14.2
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            #path: /monitor/monitor.html
            path: /index.html
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 3
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        #readinessProbe:                    #探针类型
        #  httpGet:                            #探针方式
        #    #path: /monitor/monitor.html   #测试地址
        #    path: /index.html
        #    port: 80
        #  initialDelaySeconds: 5           #参数
        #  periodSeconds: 3
        # timeoutSeconds: 5
        # successThreshold: 1
        # failureThreshold: 3  
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: magedu-nginx-service-label
  name: magedu-nginx-service
  namespace: default
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30004
  selector:
    app: nginx-linux39


#说明重启过多次。目前状态为CrashLoopBackOff
[root@localhost7C ~]# kubectl  get pod -o wide
NAME                              READY   STATUS             RESTARTS   AGE     IP           NODE                      NOMINATED NODE   READINESS GATES
nginx-deployment-67c7cf88-m5nqt   0/1     CrashLoopBackOff   4          2m24s   10.10.3.54   localhost7f.localdomain   <none>           <none>

 

示例:readinessProbe和HTTPGetAction:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-linux39
  template:
    metadata:
      labels:
        app: nginx-linux39
    spec:
      containers:
      - name: nginx
        image: harbor.linux39.com/baseimages/nginx:1.14.2
        ports:
        - containerPort: 80
        readinessProbe:
          httpGet:
            #path: /monitor/monitor.html  #测试
            path: /index.html
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 3
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        #livenessProbe:
        #  httpGet:
        #    #path: /monitor/monitor.html
        #    path: /index.html
        #    port: 80
        #  initialDelaySeconds: 5
        #  periodSeconds: 3
        #  timeoutSeconds: 5
        #  successThreshold: 1
        #  failureThreshold: 3
          
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: magedu-nginx-service-label
  name: magedu-nginx-service
  namespace: default
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30004
  selector:
    app: nginx-linux39



#容器正常
[root@localhost7C ~]# kubectl  get pod -o wide
NAME                                READY   STATUS    RESTARTS   AGE     IP           NODE                      NOMINATED NODE   READINESS GATES
nginx-deployment-6b9856b557-cnsvd   0/1     Running   0          3m12s   10.10.3.55   localhost7f.localdomain   <none>           <none>

#Endpoints:删除
[root@localhost7C ~]# kubectl  describe  services -n default magedu-nginx-service
Name:                     magedu-nginx-service
Namespace:                default
Labels:                   app=magedu-nginx-service-label
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"magedu-nginx-service-label"},"name":"magedu-nginx-servic...
Selector:                 app=nginx-linux39
Type:                     NodePort
IP:                       10.20.101.71
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  30004/TCP
Endpoints:                
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

#显示错误 
[root@localhost7C ~]# kubectl  describe  pod nginx-deployment-6b9856b557-cnsvd 
   ...
   ...
Warning  Unhealthy  57s (x48 over 3m18s)  kubelet, localhost7f.localdomain  Readiness probe failed: HTTP probe failed with statuscode: 404

 

#TCPSocketAction处理方式,结果一样。
[root@localhost7C case5]# cat nginx-tcp.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-linux39
  template:
    metadata:
      labels:
        app: nginx-linux39
    spec:
      containers:
      - name: nginx
        image: harbor.linux39.com/baseimages/nginx:1.14.2
        ports:
        - containerPort: 80
        livenessProbe:
          tcpSocket:   #tcp方式
            port: 80  
            #port: 8080
          initialDelaySeconds: 5
          periodSeconds: 3
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        readinessProbe:
          tcpSocket:    #tcp方式
            port: 80
            #port: 8080
          initialDelaySeconds: 5
          periodSeconds: 3
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3

---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: magedu-nginx-service-label
  name: magedu-nginx-service
  namespace: default
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30004
  selector:
    app: nginx-linux39

 

#ExecAction:处理方式,结果一样。
[root@localhost7C case5]# cat redis-ExecAction.yml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deployment
  labels:
    app: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-linux39
  template:
    metadata:
      labels:
        app: redis-linux39
    spec:
      containers:
      - name: redis
        image: redis:4.0.14 
        ports:
        - containerPort: 6379
        livenessProbe:
          exec:                #ExecAction:处理方式
            command:
            #- /apps/redis/bin/redis-cli
            - /usr/local/bin/redis-cli
            - quit
          initialDelaySeconds: 5
          periodSeconds: 3
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        readinessProbe:
          exec:                #ExecAction:处理方式
            command:
            #- /apps/redis/bin/redis-cli   #错误路径
            - /usr/local/bin/redis-cli 
            - quit
          initialDelaySeconds: 5
          periodSeconds: 3
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: magedu-redis-service-label
  name: magedu-redis-service
  namespace: default
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 6379
    nodePort: 30005
  selector:
    app: redis-linux39

 

k8s在Pod出现异常的时候会自动将Pod重启以恢复Pod中的服务,Pod重启策略。
restartPolicy:
    Always:    当容器异常时,k8s自动重启该容器,ReplicationController/Replicaset/Deployment。
    OnFailure: 当容器失败时(容器停止运行且退出码不为0),k8s自动重启该容器。
    Never:        不论容器运行状态如何都不会重启该容器,Job或CronJob。

[root@localhost7C case5]# cat redis-ExecAction.yml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deployment
  labels:
    app: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-linux39
  template:
    metadata:
      labels:
        app: redis-linux39
    spec:
      containers:
      - name: redis
        image: redis:4.0.14 
        ports:
        - containerPort: 6379
        livenessProbe:
          exec:                #ExecAction:处理方式
            command:
            - /apps/redis/bin/redis-cli        #错误路径
            #- /usr/local/bin/redis-cli
            - quit
          initialDelaySeconds: 5
          periodSeconds: 3
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        readinessProbe:
          exec:                #ExecAction:处理方式
            command:
            - /apps/redis/bin/redis-cli      #错误路径 
            #- /usr/local/bin/redis-cli 
            - quit
          initialDelaySeconds: 5
          periodSeconds: 3
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
      restartPolicy: Always

---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: magedu-redis-service-label
  name: magedu-redis-service
  namespace: default
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 6379
    nodePort: 30005
  selector:
    app: redis-linux39

#当配合两种探针时,一直循环重启
[root@localhost7C ~]# kubectl  get pod -o wide
NAME                                READY   STATUS             RESTARTS   AGE   IP           NODE                      NOMINATED NODE   READINESS GATES
redis-deployment-6c594c6dd6-8dpst   0/1     CrashLoopBackOff   12         21m   10.10.3.63   localhost7f.localdomain   <none>           <none>

 

我们在日常的集群维护中经常使用 kubectl get pod 查看pod的状态。
状态值    含义
CrashLoopBackOff            容器退出,kubelet正在将它重启
Terminating                    结束
completed                    job资源正常启动
InvalidImageName            无法解析镜像名称
ImageInspectError            无法校验镜像
ErrImageNeverPull            策略禁止拉取镜像
ImagePullBackOff            正在重试拉取
RegistryUnavailable            连接不到镜像仓库(如:harbor)
ErrImagePull                拉取镜像出错
CreateContainerConfigError    不能创建kubelet使用的容器配置
CreateContainerError        创建容器失败
m.internalLifecycle.PreStartContainer    执行hook报错
RunContainerError            启动容器失败
PostStartHookError            执行hook报错
ContainersNotInitialized    容器没有初始化完毕
ContainersNotReady            容器没有准备完毕
ContainerCreating            容器创建中
PodInitializing    pod         初始化中
DockerDaemonNotReady        docker还没有完全启动
NetworkPluginNotReady        网络插件还没有完全启动
Evicted                        即驱赶(当节点出现异常时,kubernetes将有相应的
Pending:        #正在创建Pod但是Pod中的容器还没有全部被创建完成,处于此状态的Pod应该检查Pod依赖的存储是否有权限挂载、镜像是否可以下载、调度是否正常等。
Failed            #Pod中有容器启动失败而导致pod工作异常。
Unknown            #由于某种原因无法获得pod的当前状态,通常是由于与pod所在的node节点通信错误。
Succeeded        #Pod中的所有容器都被成功终止即pod里所有的containers均已terminated。
Unschedulable: #Pod不能被调度,kube-scheduler没有匹配到合适的node节点
PodScheduled    #pod正处于调度中,在kube-scheduler刚开始调度的时候,还没有将pod分配到指定的pid,在筛选出合适的节点后就会更新etcd数据,将pod分配到指定的pod
Initialized        #所有pod中的初始化容器已经完成了
ImagePullBackOff:#Pod所在的node节点下载镜像失败
Running            #Pod内部的容器已经被创建并且启动。
Ready            #表示pod中的容器已经可以提供访问服务

 

标签:name,80,探针,app,redis,nginx,pod,重启
From: https://www.cnblogs.com/Yuanbangchen/p/17191568.html

相关文章

  • 重启apache linux
    1.启动apahce的命令:/usr/local/apache2/bin/apachectlstartapache2. 停止apache的命令:/usr/local/apache2/bin/apachectlstop 3. 重启a......
  • 服务不停宕机或重启后的测试要点
    一、机器环境情况机器A和B上分别起着服务A和B,服务A和B之间通过tcp协议通信。二、测试情况分析情况一:B机器不停服务直接关机情况下(shutdown机器),服务A处理是否正常......
  • pod 卡在Terminating状态无法删除
    处理方案:重启kubelet,如果没有删除执行强制删除处理方案:强制删除pod ......
  • Android异常重启并进入Recovery(恢复)模式的原因之一
    1、init.rc简述init.rc文件由系统第一个启动的init程序解析,此文件由语句组成,主要包含了四种类型的语句:Action,Commands,Services,Options.2、服务(services)服务是指那些需......
  • Linux 查看重启开机时间
    Linux查看重启开机时间#最近启动时间who-b#systemboot2021-12-3107:07#最后重启日期last-xreboot|head-1#机器运行时长uptime-p......
  • pod调度器
    Pod是Kubernetes集群中能够被创建和管理的最小部署单元。所以需要有工具去操作和管理它们的生命周期,这里就需要用到控制器了。Pod控制器由master的kube-controlle......
  • Pod资源需求和资源限制
    [root@masterresource]#kubectlapply-fresource-requests-demo.yaml[root@masterresource]#catresource-requests-demo.yamlapiVersion:v1kind:Podmetadat......
  • 转!!Pod中容器的健康检查
    转自--https://blog.csdn.net/u010674953/article/details/129261632 健康检查上篇文章中我们了解了Pod中容器的生命周期的两个钩子函数,PostStart与PreStop,其中PostSta......
  • Nginx重启操作
    1、杀掉Nginx进程killallnginx2、启动Nginx/usr/local/openresty/nginx/sbin/nginx-c/usr/local/openresty/nginx/conf/nginx.conf3、进程是否正常启动ps-aux|......
  • k8s——pod控制器
    前言Pod是Kubernetes集群中能够被创建和管理的最小部署单元。所以需要有工具去操作和管理它们的生命周期,这里就需要用到控制器了。Pod控制器由master的kube-cont......