首页 > 解决方案 > 调试缓慢的 Kubernetes 部署

问题描述

我们在托管的 Azure 环境中使用 K8S,在 Ubuntu 中使用 Minikube 以及在本地机器上构建的 Rancher 集群,通常,我们的部署需要大约 30 秒来拉取容器、运行并准备好。但是,我最近一次尝试创建部署(本地)需要一分钟以上,有时甚至更长时间。它是一个小型 Web 服务,与我们的其他部署非常相似。唯一(明显)的区别是使用启动探针和活跃度探针,尽管我们的其他一些服务确实有探针,但它们是不同的。

在通过提取它正在运行的 yaml 并使用 kubectl 从等式中删除 Octopus deploy 之后,一旦(单个)pod 启动,我就开始读取日志,并且正如预期的那样,启动和 liveness 探针被非常快速地调用。启动成功,集群开始调用 live probe,也成功了。但是,如果我kubectl describe在 pod 上使用,它会显示 Initialized 和 PodScheduled 为 True,但 ContainersReady(有一个容器)和 Ready 在大约一分钟内都是错误的。除了探测失败之外,我看不到会导致此问题的原因,但这些都被记录为成功。

他们最终开始工作并正常工作,但我不知道他们为什么要花这么长时间。

kind: Deployment 
apiVersion: apps/v1 
metadata: 
  name: 'redirect-files-deployments-28775' 
  labels: 
    Octopus.Kubernetes.SelectionStrategyVersion: "SelectionStrategyVersion2" 
    OtherOctopusLabels
spec: 
  replicas: 1 
  selector: 
    matchLabels: 
      Octopus.Kubernetes.DeploymentName: 'redirect-files-deployments-28775' 

  template: 
    metadata: 
      labels: 
        Octopus.Kubernetes.SelectionStrategyVersion: "SelectionStrategyVersion2" 
        OtherOctopusLabels

    spec: 
      containers: 
      - name: redirect-files 
        image: ourregistry.azurecr.io/microservices.redirectfiles:1.0.34 
        ports: 
        - name: http 
          containerPort: 80 
          protocol: TCP 
        env: 
        - removed connection strings etc
        livenessProbe: 
          httpGet: 
            path: /api/version 
            port: 80 
            scheme: HTTP 
          successThreshold: 1 
        startupProbe: 
          httpGet: 
            path: /healthcheck 
            port: 80 
            scheme: HTTP 
            httpHeaders: 
            - name: X-SS-Authorisation 
              value: asdkjlkwe098sad0akkrweklkrew 

          initialDelaySeconds: 5 
          timeoutSeconds: 5 
      imagePullSecrets: 
      - name: octopus-feedcred-feeds-azure-container-registry 

标签: kuberneteskubernetes-pod

解决方案


所以原因是启动和/或活性探测。当我删除它们时,部署时间从一分钟多到 18 秒,尽管日志证明在容器启动后很快就成功调用了探测器。

至少我现在有更具体的东西要寻找。


推荐阅读