首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹簧引导2和ReadinessProbe / LivenessProbe

弹簧引导2和ReadinessProbe / LivenessProbe
EN

Stack Overflow用户
提问于 2019-08-02 06:01:36
回答 1查看 5K关注 0票数 3

如何将我的部署配置为对sprint引导执行器端点进行健康检查?我使用的是在端口9000上运行的spring 2。(PS:前港测试工程)

这是一个错误:

代码语言:javascript
复制
Readiness probe failed: Get http://10.48.0.116:9000/actuator/health: dial tcp 10.48.0.116:9000: connect: connection refused

这就是我的部署yml:

代码语言:javascript
复制
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: my-api
  namespace: vidolin
  labels:
    stack: api
    app: my-api
spec:
  replicas: 1
  selector:
    matchLabels:
      stack: api
      app: my-api
  template:
    metadata:
      labels:
        stack: api
        app: my-api
    spec:
      imagePullSecrets:  
      - name: itdevregistry
      containers:
      - name: primary
        image: vidolinregistry.azurecr.io/my/api
        ports:
        - containerPort: 9000
        envFrom:
        - configMapRef:
            name: my-api-config
        readinessProbe:
          httpGet:
            path: /actuator/health
            port: 9000
          initialDelaySeconds: 10
          timeoutSeconds: 2
          periodSeconds: 3
          failureThreshold: 1
        livenessProbe:
          httpGet:
            path: /actuator/health
            port: 9000
          initialDelaySeconds: 20
          timeoutSeconds: 2
          periodSeconds: 8
          failureThreshold: 1
EN

回答 1

Stack Overflow用户

发布于 2019-12-24 23:58:48

虽然我的答复有点晚了。但我认为我的实现将帮助人们在未来实现kubernetes准备/活动探测spring引导应用程序。

我的码头形象描述

  1. 由阿尔卑斯linux构建
  2. Spring 2应用程序,只能通过SSL访问。
  3. 弹簧引导执行器实现/执行器/健康,返回{"status":"UP"}

所以我不能使用kubernetes的httpGet选项,因为它只使用http协议.

这就是为什么我创建一个小的shell脚本“Check-if-Health.sh”作为docker映像的一部分,以了解状态。

代码语言:javascript
复制
check-if-healthy.sh
===================
curl -k https://localhost:8888/actuator/health | grep '"status":"UP"' > /dev/null && exit 0 || exit 1

请注意,您需要将此脚本添加到docker映像中,以便它在运行的容器中可用,并可由kubernetes访问,因为kubernetes将像这样激发"docker /bin/ash“

代码语言:javascript
复制
COPY docker/check-if-healthy.sh /home/config-server/check-if-healthy.sh

然后使用kubernetes就绪探测的"exec“选项来像这样调用脚本。

代码语言:javascript
复制
      readinessProbe:
        exec:
          command:
            - /bin/ash
            - /home/config-server/check-if-healthy.sh
        initialDelaySeconds: 5
        timeoutSeconds: 1
        failureThreshold: 50
      livenessProbe:
        exec:
          command:
            - /bin/ash
            - /home/config-server/check-if-healthy.sh
        initialDelaySeconds: 5
        timeoutSeconds: 1
        failureThreshold: 50
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57320733

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档