📖 Scenario: You are managing a Kubernetes deployment for a simple web application. To ensure your application is healthy and ready to serve traffic, you need to configure a TCP readiness probe. This probe will check if the application is accepting TCP connections on a specific port.
🎯 Goal: Configure a Kubernetes pod manifest with a TCP readiness probe on port 80. This probe will help Kubernetes know when the pod is ready to receive traffic.
📋 What You'll Learn
Create a pod manifest named tcp-probe-pod.yaml with a container named webapp.
Set the container image to nginx:latest.
Add a readiness probe using TCP socket on port 80.
Set initialDelaySeconds to 5 and periodSeconds to 10 for the readiness probe.
💡 Why This Matters
🌍 Real World
TCP probes are used in Kubernetes to check if an application is ready to accept network connections, which is important for load balancing and service availability.
💼 Career
Understanding how to configure readiness and liveness probes is essential for DevOps engineers and site reliability engineers to maintain healthy Kubernetes applications.
Progress0 / 4 steps
1
Create the basic pod manifest
Create a YAML file named tcp-probe-pod.yaml with a pod named tcp-probe-pod that has one container named webapp using the image nginx:latest. Include the apiVersion, kind, and metadata fields.
Kubernetes
Hint
Start with the basic pod structure and specify the container details.
2
Add the readiness probe configuration
Add a readinessProbe section under the container webapp. Configure it to use a TCP socket on port 80.
Kubernetes
Hint
Use tcpSocket under readinessProbe and specify the port number.
3
Add timing settings to the readiness probe
Add initialDelaySeconds set to 5 and periodSeconds set to 10 inside the readinessProbe configuration under the container webapp.
Kubernetes
Hint
Place these timing settings at the same level as tcpSocket inside readinessProbe.
4
Display the final pod manifest
Print the complete content of the tcp-probe-pod.yaml file to verify the readiness probe configuration.
Kubernetes
Hint
Use multiple print statements to output each line of the YAML manifest exactly as shown.
Practice
(1/5)
1. What is the main purpose of a TCP probe in Kubernetes?
easy
A. To check the container's memory usage
B. To monitor CPU usage of a container
C. To verify the container's file system integrity
D. To check if a container accepts TCP connections on a specified port
Solution
Step 1: Understand TCP probe function
A TCP probe tests if a container is accepting TCP connections on a specific port.
Step 2: Compare with other options
CPU, memory, and file system checks are not done by TCP probes but by other mechanisms.
Final Answer:
To check if a container accepts TCP connections on a specified port -> Option D
Quick Check:
TCP probe = connection check [OK]
Hint: TCP probe checks port connectivity, not resource usage [OK]
Common Mistakes:
Confusing TCP probe with CPU or memory monitoring
Thinking TCP probe checks file system health
Assuming TCP probe checks HTTP endpoints
2. Which of the following is the correct syntax to define a TCP liveness probe in a pod spec?
easy
A. livenessProbe:
tcpSocket:
path: "/health"
initialDelaySeconds: 5
periodSeconds: 10
B. livenessProbe:
httpGet:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
C. livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
D. livenessProbe:
exec:
command: ["curl", "localhost:8080"]
initialDelaySeconds: 5
periodSeconds: 10
Solution
Step 1: Identify TCP probe syntax
TCP probes use tcpSocket with a port field, no path.
Step 2: Check options for correctness
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10 uses tcpSocket with port 8080 and timing fields correctly. Others use HTTP or exec or invalid fields.
Final Answer:
livenessProbe with tcpSocket and port field -> Option C
Quick Check:
TCP probe syntax = tcpSocket + port [OK]
Hint: TCP probes use tcpSocket with port, no path [OK]
Common Mistakes:
Using httpGet or exec instead of tcpSocket for TCP probes
Adding a path field to tcpSocket (invalid)
Omitting port number in tcpSocket
3. Given this pod spec snippet, what will happen if the container does not accept TCP connections on port 3306?
4. You configured a TCP readiness probe but Kubernetes reports probe failures immediately after pod start. Which is the most likely cause?
medium
A. initialDelaySeconds is missing or too low, so probe runs before container is ready
B. tcpSocket port is set to 0, which is invalid
C. periodSeconds is set too high, causing delayed checks
D. readinessProbe cannot use tcpSocket, only httpGet
Solution
Step 1: Analyze probe timing parameters
Without initialDelaySeconds, probe starts immediately, possibly before container is ready.
Step 2: Evaluate other options
Port 0 is invalid but would cause different errors; periodSeconds affects frequency, not immediate failure; tcpSocket is valid for readiness probes.
Final Answer:
initialDelaySeconds is missing or too low, so probe runs before container is ready -> Option A
Quick Check:
Missing initialDelaySeconds = early probe failure [OK]
Hint: Set initialDelaySeconds to delay probe start [OK]
Common Mistakes:
Assuming tcpSocket is invalid for readiness probes
Ignoring initialDelaySeconds importance
Confusing periodSeconds with initialDelaySeconds
5. You want to configure a TCP readiness probe for a database container on port 5432. The container takes about 20 seconds to start accepting connections. Which configuration is best to avoid false failures?