0

我做了一个 nginx pod 的简单部署,然后编辑了部署以通过 TCP 添加一个 readinessProbe 和一个 livenessProbe,就像在官方文档中一样。

保存后,部署创建了一个新的副本集并启动了新的 pod,但探测从未完成。

这是 describe 命令的部署 yaml 输出:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "2"
  creationTimestamp: "2020-09-21T18:51:13Z"
  generation: 2
  labels:
    app: dep1
  name: dep1
  namespace: default
  resourceVersion: "1683893"
  selfLink: /apis/apps/v1/namespaces/default/deployments/dep1
  uid: b23bceff-aca5-4c89-84c0-5882cf2df217
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: dep1
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: dep1
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          initialDelaySeconds: 15
          periodSeconds: 20
          successThreshold: 1
          tcpSocket:
            port: 8080
          timeoutSeconds: 1
        name: nginx
        ports:
        - containerPort: 8080
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          tcpSocket:
            port: 8080
          timeoutSeconds: 1
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: "2020-09-21T18:51:16Z"
    lastUpdateTime: "2020-09-21T18:51:16Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: "2020-09-21T18:51:13Z"
    lastUpdateTime: "2020-09-21T19:16:07Z"
    message: ReplicaSet "dep1-5d66c67794" is progressing.
    reason: ReplicaSetUpdated
    status: "True"
    type: Progressing
  observedGeneration: 2
  readyReplicas: 1
  replicas: 2
  unavailableReplicas: 1
  updatedReplicas: 1

以下是 pod 的事件:

Events:
  Type     Reason     Age                     From                     Message
  ----     ------     ----                    ----                     -------
  Normal   Scheduled  <unknown>               default-scheduler        Successfully assigned default/dep1-5d66c67794-qd48q to docker-desktop
  Normal   Pulling    13m (x2 over 14m)       kubelet, docker-desktop  Pulling image "nginx"
  Normal   Killing    13m                     kubelet, docker-desktop  Container nginx failed liveness probe, will be restarted
  Normal   Pulled     13m (x2 over 14m)       kubelet, docker-desktop  Successfully pulled image "nginx"
  Normal   Created    13m (x2 over 14m)       kubelet, docker-desktop  Created container nginx
  Normal   Started    13m (x2 over 14m)       kubelet, docker-desktop  Started container nginx
  Warning  Unhealthy  12m (x5 over 14m)       kubelet, docker-desktop  Liveness probe failed: dial tcp 10.1.0.174:8080: connect: connection refused
  Warning  Unhealthy  9m48s (x30 over 14m)    kubelet, docker-desktop  Readiness probe failed: dial tcp 10.1.0.174:8080: connect: connection refused
  Warning  BackOff    4m42s (x11 over 8m36s)  kubelet, docker-desktop  Back-off restarting failed container

当我使用以下打开端口时,为什么连接被拒绝?

ports:
  - containerPort: 8080
    protocol: TCP
4

1 回答 1

2

默认情况下,nginx webserver 暴露端口 80,不仅你的健康检查不起作用,而且你的应用程序永远不会在端口 8080 上打开。本教程中使用的 docker 镜像是k8s.gcr.io/goproxy:0.1,你正在使用nginx. 尝试此配置或将您的映像部署更改为k8s.gcr.io/goproxy:0.1

spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    livenessProbe:
      failureThreshold: 3
      initialDelaySeconds: 15
      periodSeconds: 20
      successThreshold: 1
      tcpSocket:
        port: 80
      timeoutSeconds: 1
    name: nginx
    ports:
    - containerPort: 80
      protocol: TCP
    readinessProbe:
      failureThreshold: 3
      initialDelaySeconds: 5
      periodSeconds: 10
      successThreshold: 1
      tcpSocket:
        port: 80
      timeoutSeconds: 1
于 2020-09-21T20:14:14.773 回答