【问题标题】:How to check logs for deployment?如何检查日志以进行部署?
【发布时间】:2019-05-30 22:17:55
【问题描述】:

我正在尝试部署一个使用 postgres 数据库的 Spring Boot 应用程序。

我使用了这个教程: https://github.com/mkjelland/spring-boot-postgres-on-k8s-sample

但是当我执行这个命令时

 kubectl expose deployment spring-boot-postgres-sample --type=LoadBalancer -- 
  port=8080

所以它提供外部 IP 状态大约 30 分钟

所以我使用

来修补它
kubectl patch svc <svc-name> -n <namespace> -p '{"spec": {"type": "LoadBalancer", "externalIPs":["172.31.71.218"]}}'

因此,当我尝试访问正在超时的http://172.31.71.218:8080 时。

我想查看幕后发生的日志。

我也尝试通过使用 yaml 文件来使用集群 IP 服务

    apiVersion: v1
kind: Service
metadata:
  labels:
    app: spring-boot-postgres-sample
  name: spring-boot-postgres-sample
  namespace: default
spec:
  ports:
  - nodePort: 30500
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: spring-boot-postgres-sample
  type: NodePort

使用以下命令:-

kubectl create -f service.yaml

然后尝试访问 http://myhostip:30500/

但仍然超时 我如何检查它的日志

这是 kubectl describe pod podname

的输出
    Name:               spring-boot-postgres-sample-7f7c7479d9-fclwb
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               ip-172-31-11-87/172.31.11.87
Start Time:         Thu, 30 May 2019 11:50:24 +0000
Labels:             app=spring-boot-postgres-sample
                    pod-template-hash=7f7c7479d9
Annotations:        <none>
Status:             Running
IP:                 192.168.1.28
Controlled By:      ReplicaSet/spring-boot-postgres-sample-7f7c7479d9
Containers:
  spring-boot-postgres-sample:
    Container ID:  docker://a1278cc26a66eb3b977cf1946d1490c7c5066e9fe0db8c468fd0e8dc47de5ca2
    Image:         djtijare/a2i-web:v1
    Image ID:      docker-pullable://djtijare/a2i-web@sha256:cbeac029eb3b65760b904e93ced0b417eca349280ba5a809de713d5fbb2d608f
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/bash
      -ce
      tail -f /dev/null
    State:          Running
      Started:      Thu, 30 May 2019 11:50:46 +0000
    Ready:          True
    Restart Count:  0
    Environment:
      POSTGRES_USER:      <set to the key 'postgres_user' of config map 'postgres-config'>      Optional: false
      POSTGRES_PASSWORD:  <set to the key 'postgres_password' of config map 'postgres-config'>  Optional: false
      POSTGRES_HOST:      <set to the key 'postgres_host' of config map 'hostname-config'>      Optional: false
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6pksq (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6pksq:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6pksq
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>
aquilak8suser@ip-172-31-6-149:~/a2i-web$ kubectl describe pod spring-boot-postgres-sample-7f7c7479d9-fclwb
Name:               spring-boot-postgres-sample-7f7c7479d9-fclwb
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               ip-172-31-11-87/172.31.11.87
Start Time:         Thu, 30 May 2019 11:50:24 +0000
Labels:             app=spring-boot-postgres-sample
                    pod-template-hash=7f7c7479d9
Annotations:        <none>
Status:             Running
IP:                 192.168.1.28
Controlled By:      ReplicaSet/spring-boot-postgres-sample-7f7c7479d9
Containers:
  spring-boot-postgres-sample:
    Container ID:  docker://a1278cc26a66eb3b977cf1946d1490c7c5066e9fe0db8c468fd0e8dc47de5ca2
    Image:         djtijare/a2i-web:v1
    Image ID:      docker-pullable://djtijare/a2i-web@sha256:cbeac029eb3b65760b904e93ced0b417eca349280ba5a809de713d5fbb2d608f
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/bash
      -ce
      tail -f /dev/null
    State:          Running
      Started:      Thu, 30 May 2019 11:50:46 +0000
    Ready:          True
    Restart Count:  0
    Environment:
      POSTGRES_USER:      <set to the key 'postgres_user' of config map 'postgres-config'>      Optional: false
      POSTGRES_PASSWORD:  <set to the key 'postgres_password' of config map 'postgres-config'>  Optional: false
      POSTGRES_HOST:      <set to the key 'postgres_host' of config map 'hostname-config'>      Optional: false
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6pksq (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-6pksq:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6pksq
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    您可以使用以下命令获取部署日志

    kubectl logs -f deployment/spring-boot-postgres-sample
    

    或者,如果您想要特定 pod 的日志

    kubectl logs -f spring-boot-postgres-sample-7f7c7479d9-fclwb
    

    【讨论】:

    • 它没有打印任何东西,它只是卡在那里
    • 我不知道您在做什么,但您容器中的命令(取自您粘贴的 describe 命令)是 tail -f /dev/null。这就是您看不到任何日志的原因。
    • 我刚刚从某个站点复制了 yaml。我是 kubernets 的新手。请给我一些在 kubernetes 上部署 spring boot 应用程序和 postgres 的链接。
    • Google 中的第一个结果看起来很有希望,例如 itnext.io/…gorillalogic.com/blog/…
    猜你喜欢
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多