You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何查询Kubernetes对象的全部已应用配置历史?

Can I query the full applied configuration history of a specific Kubernetes object?

Great question! Kubernetes doesn’t keep a native, easy-to-access full history of applied configurations for every object type by default, but there are solid ways to track and retrieve historical changes depending on what resource you’re working with and your cluster setup. Let’s break this down with your nginx Pod example:

1. For resources supporting rollout history (Deployments, StatefulSets, DaemonSets, etc.)

If you’re working with workload controllers that support rolling updates (like Deployments, which are far more common for long-running apps than standalone Pods), Kubernetes automatically tracks revision history. You can use these commands to access it:

  • List all saved revisions for a Deployment:
    kubectl rollout history deployment/<your-deployment-name>
    
  • View the full configuration of a specific revision:
    kubectl rollout history deployment/<your-deployment-name> --revision=<revision-number>
    

This works because these controllers store configuration snapshots every time you run kubectl apply or kubectl set commands to modify the resource.

2. For standalone Pods (like your nginx-pod example)

Standalone Pods are designed as ephemeral resources, so they don’t have built-in revision tracking. But you still have options to piece together historical changes:

  • Check the latest applied config annotation: While this only shows the most recent applied configuration (which you already get with kubectl apply view-last-applied), you can verify it directly in the Pod’s metadata:
    kubectl get pod nginx-pod -o yaml | grep -A 20 "kubectl.kubernetes.io/last-applied-configuration"
    
    The --save-config flag you used during creation ensures this annotation is populated and updated on every subsequent kubectl apply—but it only retains the latest state, not a full history.
  • Audit Logs: If your cluster has audit logging enabled, every kubectl create or kubectl apply action targeting your Pod is logged with the full configuration used. You can search these logs to pull up historical config versions.
  • GitOps Workflow: If you manage your Kubernetes configs via a Git repo (e.g., with Argo CD or Flux), your Git commit history is your source of truth. You can browse commits to see every change made to the Pod’s configuration file over time.

3. Track changes with managed fields

You can inspect the managedFields section of the Pod to see which fields were modified, when, and by which tool/controller. Run:

kubectl get pod nginx-pod -o yaml --show-managed-fields

This won’t give you full historical configurations, but it helps you map out when specific changes happened and who initiated them.

内容的提问来源于stack exchange,提问作者category

火山引擎 最新活动