惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
罗磊的独立博客
博客园 - 聂微东
博客园_首页
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
量子位
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
月光博客
月光博客
T
The Exploit Database - CXSecurity.com
Google DeepMind News
Google DeepMind News
H
Help Net Security
O
OpenAI News
Blog — PlanetScale
Blog — PlanetScale
S
Security Affairs
S
Security @ Cisco Blogs
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
AI
AI
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
Cloudbric
Cloudbric
H
Heimdal Security Blog
J
Java Code Geeks
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
宝玉的分享
宝玉的分享
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
I
Intezer
GbyAI
GbyAI

Apptio

How IBM Apptio Delivers Data Center Value in the Age of AI - Apptio Managing K8s Agent Updates at Scale with Helm and Terraform - Apptio GitOps with IBM Kubecost: Preventing Argo CD Rollbacks - Apptio GitOps with IBM Kubecost: API-Driven Rightsizing - Apptio It’s Here: Meet the New IBM Apptio Report Studio – A Faster, More Intuitive Approach to Reporting - Apptio New Tech, Same Rules: Cloud Lessons for an AI Advantage - Apptio IBM Cloudability Advanced Containers for Kubernetes FinOps - Apptio The Next Era of IT Financial Management Reporting with the New IBM Apptio Report Studio - Apptio From Guesswork to Confidence: Introducing Intelligent Forecasting for Tech Spend Planning - Apptio Smarter Technology Spend with AI-Driven Financial Intelligence - Apptio Budgets Are Up, Confidence Isn't: 2026 Global Tech Investment Insights - Apptio IBM Kubecost 3.1: Kubernetes Resource Quota Rightsizing - Apptio Driving FinOps Forward in 2025 and Beyond - Apptio ITFM Maturity: The Next CIO Imperative in the Age of Innovation - Apptio How Banks Can Optimize IT Spend Without Sacrificing Impact - Apptio Introducing IBM Apptio Product TCO: Turn Product Spend into Strategic Investments with Clear, End-to-End Total Cost of Ownership and Unit Costs: Creating a Strategic Lens for IT Investment Decisions - Apptio Workforce Management: The Engine of Strategic Portfolio Management - Apptio FinOps for AI: Enabling the Next Wave of Cloud Innovation - Apptio IBM Kubecost 3.0: Faster, Smarter, and Built for Scale - Apptio Introducing IBM Apptio Mainframe TCO: Complete Visibility into Mainframe Costs and Usage - Apptio Essential K8s Cost Metrics for Reducing Spend - Apptio The New Standard for Strategic Portfolio Management: Financial Visibility at Every Level - Apptio K8s Cost Ownership: Who’s Responsible and How to Make It Work - Apptio Kubecost 2.8: Centralized Custom Pricing and a Big Performance Leap with ClickHouse - Apptio Unlock the Power of IT Financial Management with IBM Apptio Essentials - Apptio Full Transparency for Smart AI Investments with IBM Apptio’s AI Total Cost of Ownership & Usage - Apptio What’s New in IBM Apptio Planning - Apptio Labeling in Kubernetes: From Metadata to Money-Saving Insights - Apptio Innovative Approaches to Drive Tech Spend Management with AI, Analytics, and Automation - Apptio Discover Kubecost on Apptio’s Website: Enhancing FinOps with Kubernetes Insights - Apptio How Kubecost Collections Works: From the Engineers Who Built It - Apptio Kubecost 2.7 Release Highlights - Apptio Introducing Hybrid IT TCO Impact: IBM Apptio’s Newest Solution to Manage Your Evolving Hybrid Environment - Apptio FinOps Essentials: Best Practices for Finance Teams - Apptio Upgrading Your Kubecost Experience - Apptio Kubecost 2.6 Release Highlights - Apptio Kubernetes Efficiency: Cut Waste, Not Performance - Apptio FinOps Essentials: Best Practices for Product Teams - Apptio Optimizing GPU Monitoring for AI Efficiency - Apptio Kubecost 2.5 Release Highlights - Apptio FinOps Essentials: Strategies for Smarter Cloud Spending - Apptio Achieving Cost-Effective Scaling in Kubernetes - Apptio Celebrating OpenCost’s Journey to CNCF Incubation - Apptio Unlocking Technology Value: The Essential Role of TBM in Modern IT Management - Apptio The Complex Costs of AI: Investments, Funding, and ROI Tracking - Apptio Addressing Carbon Emissions in IT: The New Business Imperative - Apptio Kubecost Brings NVIDIA GPU cost monitoring for AI workloads in 2.4 - Apptio Kubecost Launches Support for Oracle Cloud - Apptio Kubecost 2.4 Release Highlights - Apptio Evolving Container Cost Visibility with IBM Cloudability - Apptio Transforming the Way You Manage Your Digital Portfolios: IBM Apptio and ServiceNow - Apptio Maximizing Kubernetes Cost Efficiency with Kubecost and Amazon EKS - Apptio FinOps Foundations: Strategies for Cross-Team Alignment - Apptio Managing Kubernetes Costs in a Multi-Cloud Environment - Apptio Unlock Kubernetes Savings with Kubecost’s Automated Actions - Apptio Celebrating a Milestone: Kubecost Surpasses 10 Million Installs - Apptio Kubernetes Pricing: On-Premises Versus Cloud Environments - Apptio Maximizing Multi-Cloud Efficiency with Kubecost APIs - Apptio Aligning Tech Financials and Labor Resources - Apptio Kubecost 2.3 Release Highlights - Apptio IBM Cloudability Introduces New Innovations for FinOps Practitioners - Apptio Kubecost Launches the First Kubecost Certification - Apptio Enhancing Cloud Reporting: Attributing Costs to Kubernetes Applications - Apptio Building a FinOps Solution for All - Apptio Navigating the Growing Complexities of Technology Spend Management - Apptio Apptio Introduces New Products to Elevate Technology Value - Apptio Developing a Strategy for Kubernetes Cost Monitoring - Apptio Visualize your Kubernetes Network Costs - Apptio Getting Highly Accurate and Granular Cost Metrics with Kubecost - Apptio 8 Steps to Achieve Enterprise Agile Planning Success - Apptio FinOps and TBM at Public Sector Summit - Apptio Introducing Kubecost Collections - Apptio Apptio & ServiceNow launch new Application Portfolio Management capabilities - Apptio Beyond the Hype: A Balanced View of AI Adoption - Apptio 2.1 Release Highlights - Apptio Starting your Technology Business Management Journey: A Guide for Smart Technology Investments with Apptio Cost Management - Apptio IBM Cloudability: 2023 Innovation in Review - Apptio Kubecost 2.0 Packaging - Apptio Kubernetes Health Check - How-To and Best Practices - Apptio Introducing Kubecost 2.0 - Apptio Kubernetes Liveness Probe: Tutorial & Examples - Apptio Kubernetes Cluster Size: Your Guide to Optimization - Apptio EKS Cost Monitoring: The Kubecost and AWS Solution - Apptio Kubernetes Deployment Strategies: Tutorial & Examples - Apptio Guide to Kubernetes Management Tools - Apptio Automate Your Rightsizing Workflows with IBM Cloudability and ServiceNow - Apptio Kyverno and Kubecost: Real-time Kubernetes Cost Management - Apptio Making Smarter IT Decisions With Apptio Plus ServiceNow Breaking Down Silos Between Finance and Agile Teams With Lean Budgeting - Apptio Maximize Cloud Savings Without Running Afoul of AWS RI Marketplace Enforcements - Apptio Cost-Effective Deployment Policies With Kyverno - Apptio Tracking Waste on Kubernetes Clusters - Apptio Blending FinOps With Observability - Apptio 3 Key Opportunities for Finance Teams in SAFe 6.0 - Apptio Kubecost Predict Part 2: Introducing the Admission Controller - Apptio The CEO as the Chief Transformation Officer - Apptio Client Challenge Client Challenge Client Challenge
Kubernetes Readiness Probe: Tutorial & Examples - Apptio
Mike Miller · 2024-02-13 · via Apptio

When developing applications running in a public cloud, containerized environments have different considerations than regular, “bare-metal” monoliths. One of these considerations is optimizing for quick container startup time, which gives the service the ability to scale in response to load quickly, minimizes idle resources, enables faster self-healing, and more. This requirement for quick startup time leads to various questions, such as how to know when a container has completed startup or when it is ready to accept traffic.

Enter Kubernetes probes, of which there are three types: liveness, readiness, and startup. This article focuses on readiness probes, which are tests deployed with your container that will stop forwarding any traffic to the pod on failure. The pod will continue to run and not serve traffic until the readiness probe succeeds.

Summary of Kubernetes probe types

Before we dive into readiness probes, let’s review the different types of Kubernetes probes for context. Each type of probe has specific use cases, and it’s essential to understand the differences between them to use them effectively.

Type of Probe Description Use Cases
Liveness A liveness probe is used to determine if a container is still running. If the probe fails, the container is restarted.
  • Detecting hung processes
  • Monitoring resource usage
  • Handling external dependencies
  • Detecting software bugs
  • Upgrading software
  • Maintaining availability
Readiness A readiness probe is used to determine if a container is ready to receive traffic. If the probe fails, the container is not sent traffic until it becomes ready again.
  • Databases
  • Web applications
  • Microservices
  • Load balancers
  • Continuous deployments
Startup A startup probe is used to determine if a container has started successfully. If the probe fails, the pod is not created.
  • Waiting for external dependencies
  • Initializing databases
  • Loading large data sets
  • Waiting for network configuration
  • Running setup scripts

What are readiness probes?

Readiness probes are a feature in Kubernetes that allow you to determine if a container is ready to receive traffic. In the event of a failed readiness probe, the kubelet continues running the container that failed the checks and runs more probes; because the check failed, the kubelet sets the Ready condition on the pod to false.

Readiness probe types

There are two types of readiness probes in Kubernetes:

  • HTTP probes send an HTTP request to a specified endpoint within the container and expect a response with a status code in the 200-400 range. The endpoint, interval, timeout, and failure threshold can be configured.
  • Command probes run a command inside the container and expect a zero exit status to indicate that the container is ready. Here, the command, interval, timeout, and failure threshold can be configured.
  • TCP probes send a TCP check on a specific port, which is successful if open.
  • gRPC probes perform a remote procedure call using gRPC.

As mentioned above, you can configure the following options for each probe:

  • Interval: The time between consecutive probes
  • Timeout: The time to wait for a response before marking the probe as failed
  • Failure threshold: The number of consecutive failures required before marking the container as not ready.

Using these configuration options, you can fine-tune your readiness probes to reflect your containers’ readiness accurately. With the use of readiness probes, you can ensure that traffic is only directed to containers that are fully initialized and ready to handle it.

Common gotchas

Watch out for these common issues when using readiness probes:

  • Misusing readiness probes may cause excessive resource consumption due to the number of processes in the container.
  • When using liveness probes and readiness probes together, one must remember that liveness probes don’t wait for readiness probes to execute. The Kubernetes probe documentation shows how to configure initialDelaySeconds to avoid this behavior.

Example use cases for a Kubernetes readiness probe

The following are some typical use cases for Kubernetes readiness probes:

  • Databases: If you have a database in a container, you can use a readiness probe to check if it’s fully initialized and ready to receive traffic before sending requests.
  • Web applications: A readiness probe can be used to check if a web application is fully loaded and ready to handle requests. This helps ensure that users are not directed to broken or incomplete pages.
  • Microservices: If you have a microservices architecture, you can use a readiness probe to determine if each microservice is ready to receive requests from other services before sending traffic to it.
  • Load balancers: When using a load balancer with a set of pods, a readiness probe can determine if a pod is ready to receive traffic before directing traffic to it.
  • Continuous deployments: If you’re deploying a new version of an application, a readiness probe can be used to confirm that the new version is fully initialized and ready to handle traffic before directing it to the latest version.

Examples

HTTP readiness probe for a web server

apiVersion: v1
kind: Pod
metadata:
  name: web-server-pod
spec:
  containers:
  - name: web-server
    image: nginx:latest
    readinessProbe:
      httpGet:
        path: /
        port: 80
      initialDelaySeconds: 5
      periodSeconds: 5
      timeoutSeconds: 1
      successThreshold: 1
      failureThreshold: 3

In this example, the web server is a container running the Nginx web server. The readiness probe periodically sends an HTTP GET request to the “/” endpoint on port 80 and expects a response with a status code in the 200-400 range. The probe waits 5 seconds before starting, runs every 5 seconds, and has a timeout of 1 second. If the probe fails three times in a row, the container is considered not ready.

Apptio IBMKubecost ProductLogotype WithIcon Pos - Kubernetes Readiness Probe: Tutorial & Examples - Apptio

Comprehensive Kubernetes cost monitoring & optimization

Install in 5 mins or less.

Command readiness probe for a database

apiVersion: v1
kind: Pod
metadata:
  name: database-pod
spec:
  containers:
  - name: database
    image: postgres:latest
    readinessProbe:
      exec:
        command:
        - psql
        - -U
        - postgres
        - -c
        - 'select 1'
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 5
      successThreshold: 1
      failureThreshold: 3

In this example, the database is a container running the Postgres database. The readiness probe runs a command using psql to execute a SQL query that selects the value 1. The probe waits 10 seconds before starting, runs every 10 seconds, and has a timeout of 5 seconds. If the probe returns a non-zero exit status three times in a row, the container will be considered not ready.

Readiness probe for a Kafka producer application

apiVersion: v1
kind: Pod
metadata:
  name: kafka-producer-pod
spec:
  containers:
  - name: kafka-producer
    image: confluentinc/cp-kafka-producer:5.5.0
    readinessProbe:
      tcpSocket:
        port: 9092
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 5
      successThreshold: 1
      failureThreshold: 3

In this example, the Kafka producer is a container running the Confluent Kafka producer. This readiness probe helps ensure that the Kafka producer only sends messages to the Kafka broker when the broker is available and ready to receive messages.

The readiness probe uses a TCP socket probe to check the availability of the Kafka broker by sending a connection request to port 9092. The probe waits 10 seconds before starting, runs every 10 seconds, and has a timeout of 5 seconds. If the probe fails three times in a row, the container will be considered not ready.

TCP readiness probe for a web server

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-webserver
spec:
  replicas: 3
  selector:
    matchLabels:
      app: webserver
  template:
    metadata:
      labels:
    	  app: webserver
    spec:
  	containers:
        - name: my-webserver-container
          image: my-webserver-image:latest
          ports:
            - containerPort: 80
          readinessProbe:
            tcpSocket:
          	   port: 80
        	 initialDelaySeconds: 10
        	 periodSeconds: 5

In this example, the web server is made up of three replica pods. The readiness probe periodically sends a TCP check against port 80 of the container every 5 seconds, starting 10 seconds after the container is started. This means that Kubernetes will only direct traffic to the container once it has confirmed that the container is listening on port 80 and ready to handle requests.

FinOps Strategies for Cost Analysis: Understanding and Reducing Your Cloud Bill

gRPC readiness probe for a microservice

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-grpc-service
spec:
  replicas: 3
  selector:
	matchLabels:
  	  app: grpc-service
  template:
	metadata:
  	labels:
    	  app: grpc-service
	spec:
  	containers:
       - name: my-grpc-container
         image: my-grpc-image:latest
         ports:
        	- containerPort: 50051
      	readinessProbe:
             exec:
          	    command:
            	- /bin/grpc_health_probe
            	- -addr=:50051
        	  initialDelaySeconds: 10
        	  periodSeconds: 5

In this example, the gRPC readiness probe is configured to perform an exec check using the grpc_health_probe command-line tool, which is commonly used to check the health of gRPC services. The probe is configured to run every 5 seconds, starting 10 seconds after the container is started. This ensures that traffic is only directed to our gRPC microservice when it’s ready to handle it

Kubernetes readiness probe tutorial

Prerequisites:

  • Minikube
  • Kubectl
  • curl

Kubecost Installation 101: Best Practices for a Seamless Setup

This example shows how a readiness probe can fail and how it affects the pod’s availability to receive traffic.

1. Start a local minikube kubernetes cluster:

minikube start

2. Create a basic deployment:

kubectl create deployment my-app --image=nginx

3. Create a readiness probe:

kubectl expose deployment my-app --port=80 --target-port=80
kubectl patch deployment my-app -p '{"spec":{"template":{"spec":{"containers":[{"name":"my-app","image":"nginx","readinessProbe":{"httpGet":{"path":"/", "port":80}}}]}}}}'`

4. If you prefer to apply from a manifest file, save the following to a file called “readiness-probe.yaml”:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
    	  name: my-app
	spec:
  	containers:
  	- name: nginx
    	image: nginx
    	readinessProbe:
      httpGet:
        	path: /
        	port: 80
      	initialDelaySeconds: 10
      	periodSeconds: 5

5. Then apply it with:

kubectl apply -f readiness-probe.yaml

6. Verify the readiness probe:

kubectl describe pod my-app

It should output the following:

Readiness Probe:
  HTTP Get http://10.1.0.43:80/ delay=0s timeout=1s period=10s #success=1 #failure=3

7. Access the app:

minikube service my-app --url

See the output:

http://192.168.39.xx:port

8. See the pod status:

Kubectl get pods

9. Now, let’s edit the readiness probe:

kubectl patch deployment my-app -p '{"spec":{"template":{"spec":{"containers":[{"name":"my-app","readinessProbe":{"httpGet":{"path":"/", "port":80, "timeoutSeconds":1}}}]}}}}'

10. Let’s also edit the container to make it fail the readiness probe:

kubectl edit deployment my-app

In the YAML file, change the command to sleep for a longer duration than the timeout:

command:
  - "sh"
  - "-c"
  - "sleep 30"

11. Save the changes and close the file.

12. Verify the status of the pod:

kubectl describe pod my-app

The output should show the status of the readiness probe:

Readiness Probe Failed: HTTP probe failed with statuscode: 504

The pod will be in a not-ready state and will not receive traffic until it becomes ready again.

Best practices

By following these best practices, you can ensure that your readiness probes effectively detect and address issues with your containers.

Use a meaningful endpoint

The endpoint used by the readiness probe should be representative of the overall readiness of the container. For example, more than a simple HTTP GET request to the root endpoint may be needed to determine if the application is fully loaded and ready to handle requests.

Choose appropriate probe parameters

The interval, timeout, and failure threshold should be set appropriately for your use case. You want the interval to be frequent enough to detect failures quickly, the timeout to be long enough for the probe to complete, and the failure threshold to be high enough to tolerate some failures before marking the container as not ready.

Use liveness probes in conjunction with readiness probes

If a container is not responding to a readiness probe, it may indicate that the container is not running or is in a degraded state. In this case, if necessary, you should use a liveness probe to detect and restart the container.

Monitor probe results

Regularly monitor the results of your readiness probes to detect issues early and identify any potential performance bottlenecks.

Avoid overloading containers

Be careful not to overload containers with traffic while they are still initializing. This can cause the readiness probe to fail and may result in the container being marked as not ready.

Test probes in various scenarios

Regularly test your probes in different scenarios and ensure that the readiness probe represents the overall system, not just the individual container.

Conclusion

By now, you should have a clear understanding of the benefits of using readiness probes in Kubernetes. Additionally, you have seen through examples that setting them up is not complicated, even though there are some common gotchas to be aware of. Armed with this knowledge, you can confidently implement readiness probes in your Kubernetes clusters to ensure that your applications are performing optimally and reliably.