kubectl日志不返回任何内容(空白)

时间:2019-01-10 18:37:26

标签: kubernetes kubectl azure-aks

kubectl logs web-deployment-76789f7f64-s2b4r

什么也不返回!控制台提示符返回,没有错误。

我有一个处于CrashLoopbackOff周期(但无法诊断)的豆荚->

web-deployment-7f985968dc-rhx52       0/1       CrashLoopBackOff   6          7m

我在Windows上将Azure AKS与kubectl一起使用。我已经运行了几个月没有问题的集群。使用docker-compose,该容器在我的工作站上运行良好。

kubectl describe并没有太大帮助-那里没有有用的信息。

kubectl describe pod web-deployment-76789f7f64-s2b4r

Name:           web-deployment-76789f7f64-j6z5h
Namespace:      default
Node:           aks-nodepool1-35657602-0/10.240.0.4
Start Time:     Thu, 10 Jan 2019 18:58:35 +0000
Labels:         app=stweb
                pod-template-hash=3234593920
Annotations:    <none>
Status:         Running
IP:             10.244.0.25
Controlled By:  ReplicaSet/web-deployment-76789f7f64
Containers:
  stweb:
    Container ID:   docker://d1e184a49931bd01804ace51cb44bb4e3479786ec0df6e406546bfb27ab84e31
    Image:          virasana/stwebapi:2.0.20190110.20
    Image ID:       docker-pullable://virasana/stwebapi@sha256:2a1405f30c358f1b2a2579c5f3cc19b7d3cc8e19e9e6dc0061bebb732a05d394
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 10 Jan 2019 18:59:27 +0000
      Finished:     Thu, 10 Jan 2019 18:59:27 +0000
    Ready:          False
    Restart Count:  3
    Environment:
      SUPPORT_TICKET_DEPLOY_DB_CONN_STRING_AUTH:  <set to the key 'SUPPORT_TICKET_DEPLOY_DB_CONN_STRING_AUTH' in secret 'mssql'>  Optional: false
      SUPPORT_TICKET_DEPLOY_DB_CONN_STRING:       <set to the key 'SUPPORT_TICKET_DEPLOY_DB_CONN_STRING' in secret 'mssql'>       Optional: false
      SUPPORT_TICKET_DEPLOY_JWT_SECRET:           <set to the key 'SUPPORT_TICKET_DEPLOY_JWT_SECRET' in secret 'mssql'>           Optional: false
      KUBERNETES_PORT_443_TCP_ADDR:               kscluster-rgksk8s-2cfe9c-8af10e3f.hcp.eastus.azmk8s.io
      KUBERNETES_PORT:                            tcp://kscluster-rgksk8s-2cfe9c-8af10e3f.hcp.eastus.azmk8s.io:443
      KUBERNETES_PORT_443_TCP:                    tcp://kscluster-rgksk8s-2cfe9c-8af10e3f.hcp.eastus.azmk8s.io:443
      KUBERNETES_SERVICE_HOST:                    kscluster-rgksk8s-2cfe9c-8af10e3f.hcp.eastus.azmk8s.io
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-98c7q (ro)
Conditions:
  Type           Status
  Initialized    True 
  Ready          False 
  PodScheduled   True 
Volumes:
  default-token-98c7q:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-98c7q
    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:
  Type     Reason                 Age               From                               Message
  ----     ------                 ----              ----                               -------
  Normal   Scheduled              1m                default-scheduler                  Successfully assigned web-deployment-76789f7f64-j6z5h to aks-nodepool1-35657602-0
  Normal   SuccessfulMountVolume  1m                kubelet, aks-nodepool1-35657602-0  MountVolume.SetUp succeeded for volume "default-token-98c7q"
  Normal   Pulled                 24s (x4 over 1m)  kubelet, aks-nodepool1-35657602-0  Container image "virasana/stwebapi:2.0.20190110.20" already present on machine
  Normal   Created                22s (x4 over 1m)  kubelet, aks-nodepool1-35657602-0  Created container
  Normal   Started                22s (x4 over 1m)  kubelet, aks-nodepool1-35657602-0  Started container
  Warning  BackOff                7s (x6 over 1m)   kubelet, aks-nodepool1-35657602-0  Back-off restarting failed container

关于如何进行的任何想法?

非常感谢!

2 个答案:

答案 0 :(得分:2)

我正在使用多阶段docker构建,并且使用错误的目标进行构建! (我已经克隆了以前的Visual Studio docker构建任务,该任务具有以下参数:

--target=test

由于“测试”构建阶段没有定义的入口点,因此容器正在启动,然后退出而不记录任何内容!这就是 kubectl日志返回空白的原因。

我将其更改为

--target=final

一切正常!

我的Dockerfile看起来像这样:

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk AS build

WORKDIR /src

COPY . .

WORKDIR "/src"

RUN dotnet clean ./ST.Web/ST.Web.csproj
RUN dotnet build ./ST.Web/ST.Web.csproj -c Release -o /app

FROM build AS test
RUN dotnet tool install -g dotnet-reportgenerator-globaltool
RUN chmod 755 ./run-tests.sh && ./run-tests.sh

FROM build AS publish
RUN dotnet publish ./ST.Web/ST.Web.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ST.Web.dll"]

答案 1 :(得分:1)

可能是因为吊舱已经被破坏,请尝试做

kubectl logs web-deployment-76789f7f64-s2b4r --previous

这将显示上一个窗格中的日志。