如何用java触发kubernetes pod失败?

问题描述 投票:-3回答:1

我尝试使用此代码片段,但它无法解决:

@ResponseBody
@GetMapping(FAIL)
public Response triggerError(){
    i = i+1;
    if(i==3){
        i=0;
        return Response.serverError().entity("Triggered 500").build();
    }
    return Response.ok().entity("I am fine").build();
}

如何触发kubernetes pod的不健康状态?

java kubernetes health-monitoring
1个回答
0
投票

根据documentation,如果Pod是不健康的,那么pod中的容器将重新启动(或不启动),相应于restart policy

默认情况下,如果Pod中的一个容器退出并显示错误状态,则认为Pod不健康。

如果Pod不断重启,其状态显示为CrashLoopBackOff。 如果Pod中的容器以0退出,则会获得状态Completed,并且不会再进行重新启动。

您可以使用liveliness探针语法自定义Pod运行状况检查:

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5

说明:

对于Container的生命的前30秒,有一个/ tmp / health文件。因此,在前30秒,命令cat / tmp / healthy返回成功代码。 30秒后,cat / tmp / healthy返回失败代码。

我希望它会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.