Helm Chart Spring Boot 应用程序启动后立即关闭

问题描述 投票:0回答:2

我正在尝试使用 Helm Chart 在 kubernetes 集群上部署 Spring Boot 微服务。但我注意到一个奇怪的问题,我的 Spring Boot 应用程序启动,但之后立即关闭

这是日志

Started JhooqK8sApplication in 3.431 seconds (JVM running for 4.149)
2020-06-25 20:57:24.460  INFO 1 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-06-25 20:57:24.469  INFO 1 --- [extShutdownHook] o.e.jetty.server.AbstractConnector       : Stopped ServerConnector@548a102f{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2020-06-25 20:57:24.470  INFO 1 --- [extShutdownHook] org.eclipse.jetty.server.session         : node0 Stopped scavenging
2020-06-25 20:57:24.474  INFO 1 --- [extShutdownHook] o.e.j.s.h.ContextHandler.application     : Destroying Spring FrameworkServlet 'dispatcherServlet'
2020-06-25 20:57:24.493  INFO 1 --- [extShutdownHook] o.e.jetty.server.handler.ContextHandler  : Stopped o.s.b.w.e.j.JettyEmbeddedWebAppContext@56528192{application,/,[file:///tmp/jetty-docbase.4637295322181051129.8080/],UNAVAILABLE}

Spring Boot版本:2.2.7.RELEASE Docker Hub Spring Boot 公共镜像:rahulwagh17/kubernetes:jhooq-k8s-springboot-jetty

当我手动使用 kubectl 命令来创建部署和服务 Spring Boot 部署时,我注意到一件奇怪的事情,一切都很好。

vagrant@kmaster:~$ kubectl create deployment demo --image=rahulwagh17/kubernetes:jhooq-k8s-springboot-jetty

vagrant@kmaster:~$ kubectl expose deployment demo --type=LoadBalancer --name=demo-service --external-ip=1.1.1.1 --port=8080

(我按照本指南在 kubernete 上部署 spring boot - 在 kubernetes 集群上部署 spring boot

我只是想知道弹簧靴或我的头盔设置有问题吗?

这是我的头盔模板 -

---
# Source: springboot/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: RELEASE-NAME-springboot
  labels:
    helm.sh/chart: springboot-0.1.0
    app.kubernetes.io/name: springboot
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm
---
# Source: springboot/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: RELEASE-NAME-springboot
  labels:
    helm.sh/chart: springboot-0.1.0
    app.kubernetes.io/name: springboot
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: springboot
    app.kubernetes.io/instance: RELEASE-NAME
---
# Source: springboot/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: RELEASE-NAME-springboot
  labels:
    helm.sh/chart: springboot-0.1.0
    app.kubernetes.io/name: springboot
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: springboot
      app.kubernetes.io/instance: RELEASE-NAME
  template:
    metadata:
      labels:
        app.kubernetes.io/name: springboot
        app.kubernetes.io/instance: RELEASE-NAME
    spec:
      serviceAccountName: RELEASE-NAME-springboot
      securityContext:
        {}
      containers:
        - name: springboot
          securityContext:
            {}
          image: "rahulwagh17/kubernetes:jhooq-k8s-springboot-jetty"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {}
---
# Source: springboot/templates/tests/test-connection.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "RELEASE-NAME-springboot-test-connection"
  labels:
    helm.sh/chart: springboot-0.1.0
    app.kubernetes.io/name: springboot
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm
  annotations:
    "helm.sh/hook": test-success
spec:
  containers:
    - name: wget
      image: busybox
      command: ['wget']
      args: ['RELEASE-NAME-springboot:80']
  restartPolicy: Never

java spring spring-boot kubernetes kubernetes-helm
2个回答
2
投票

2020-06-25 20:57:24.469 信息 1 --- [extShutdownHook] o.e.jetty.server.AbstractConnector : 已停止 ServerConnector@548a102f{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}

         ports:
           - name: http
             containerPort: 80

看来活性探针(配置为联系名为

http
的端口)正在杀死您的 Pod,因为您的容器似乎正在侦听:8080,但您已经告诉 kubernetes 它正在侦听:80

由于

kubectl
创建的部署不会有任何此类特殊性,因此 kubernetes 不会使用活性探针,您就这样了

如果您想测试该理论,通常可以通过环境变量配置 spring 应用程序:

      containers:
        - name: springboot
          env:
          - name: SERVER_PORT
            value: '80'
          # and its friend, which is the one that 
          # you should be using for liveness and readiness
          - name: MANAGEMENT_SERVER_PORT
            value: '8080'
          securityContext:
            {}
          image: "rahulwagh17/kubernetes:jhooq-k8s-springboot-jetty"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP

0
投票

现在回答可能已经太晚了,但是使用最新的 Springboot 版本 3.5.1 和执行器,我遇到了同样的问题响应 404。 原因是,如果在 Kubernetes 清单中启用探测,则会命中默认的 HTTP 端点。但是,我建议将就绪和活跃端点指向实际的执行器运行状况端点:

          ports:
        - name: http
          containerPort: 8080
          protocol: TCP
      livenessProbe:
        httpGet:
          path: /actuator/health/liveness #This specific endpoint 
          port: http
        initialDelaySeconds: 20
      readinessProbe:
        httpGet:
          path: /actuator/health/readiness #This is specific endpoint
          port: http
        initialDelaySeconds: 20

它将返回 200 Ok。

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