<p>I made a simple deployment of an nginx pod and afterwards edited the deployment to add a readinessProbe and a livenessProbe via TCP like in the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-tcp-liveness-probe" rel="nofollow noreferrer">official docs</a>.</p>
<p>Once I save it the deployment created a new replicaSet and started the new pod, but the probes never get fulfilled.</p>
<p>Here is the deployment yaml output of the describe command:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: &quot;2&quot;
  creationTimestamp: &quot;2020-09-21T18:51:13Z&quot;
  generation: 2
  labels:
    app: dep1
  name: dep1
  namespace: default
  resourceVersion: &quot;1683893&quot;
  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: &quot;2020-09-21T18:51:16Z&quot;
    lastUpdateTime: &quot;2020-09-21T18:51:16Z&quot;
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: &quot;True&quot;
    type: Available
  - lastTransitionTime: &quot;2020-09-21T18:51:13Z&quot;
    lastUpdateTime: &quot;2020-09-21T19:16:07Z&quot;
    message: ReplicaSet &quot;dep1-5d66c67794&quot; is progressing.
    reason: ReplicaSetUpdated
    status: &quot;True&quot;
    type: Progressing
  observedGeneration: 2
  readyReplicas: 1
  replicas: 2
  unavailableReplicas: 1
  updatedReplicas: 1
</code></pre>
<p>And here are the events of the pod:</p>
<pre><code>Events:
  Type     Reason     Age                     From                     Message
  ----     ------     ----                    ----                     -------
  Normal   Scheduled  &lt;unknown&gt;               default-scheduler        Successfully assigned default/dep1-5d66c67794-qd48q to docker-desktop
  Normal   Pulling    13m (x2 over 14m)       kubelet, docker-desktop  Pulling image &quot;nginx&quot;
  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 &quot;nginx&quot;
  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
</code></pre>
<p>Why is the connection refused when I opened the ports with the following?</p>
<pre><code>ports:
  - containerPort: 8080
    protocol: TCP
</code></pre>

Heikkisorsa
<p>By default, nginx webserver exposes the port 80, not just your health checks aren't working but your application will never open on port 8080. The docker image used in this <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-tcp-liveness-probe" rel="nofollow noreferrer">tutorial</a> is <code>k8s.gcr.io/goproxy:0.1</code>, you are using <code>nginx</code>. Try this config or change your image deployment to <code>k8s.gcr.io/goproxy:0.1</code>:</p>
<pre><code>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
</code></pre>
