liveBook · Manning

TCP socket probe

As explained in Kubernetes in Action, Second Edition

A TCP socket probe is a Kubernetes container probe that checks whether a TCP connection can be established on a specified port.

A TCP socket probe checks whether Kubernetes can establish a TCP connection to a specified port on a container. A successful connection means the probe succeeds; failure to connect within the allowed time means failure. section 6.2.2 section 6.2.5

Use this probe for applications that accept TCP connections but do not expose an HTTP health-check endpoint. Unlike an exec probe, it does not run a command inside the container. section 6.2.5

    livenessProbe:
      tcpSocket:            #1
        port: 1234          #1
      periodSeconds: 2          #2
      failureThreshold: 1     #3

This configuration checks port 1234 every two seconds. One failed attempt is enough to mark the container unhealthy. section 6.2.5

The same TCP connection test can serve different lifecycle purposes:

  • As a liveness probe, failure marks the container unhealthy; Kubernetes terminates it and may restart it according to the restart policy. section 6.2.2
  • As a readiness probe, successful connection marks the container ready, while failure removes its pod from matching Services. section 11.6.1
  • Readiness timing can use initialDelaySeconds, periodSeconds, failureThreshold, timeoutSeconds, and successThreshold; successThreshold applies specifically to readiness. section 11.6.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines connection success and failure, demonstrates timing fields, and distinguishes lifecycle effects without detailing implementation internals.
Examples
Uses a liveness configuration that probes container port 1234 every two seconds with a failure threshold of one.
What it assumes
Assumes a container exposes a TCP port and introduces probe choice through HTTP, TCP socket, and exec alternatives.
What you can do after
Configure TCP-based liveness or readiness checks and distinguish container recovery from Service endpoint routing.
How it connects
Connects TCP socket probes with liveness probes, readiness probes, startup probes, Services, and exec probes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.