Hal*_*eir 4 kubernetes kubectl
We're trying to build some simple automation to detect if a deployment has finished a rolling update or not, or if a rolling update has failed. The naive way (which we do today) is to simply get all the pods for the deployment, and wait until they're ready. We look at all the pods, and if one of the pods have restarted 3 or more times (since we started the update), we roll back the update. This works fine most of the time. The times it doesn't, is when the current version that is deployed is in a failing state for any reason, so that the existing pods are continuously restarting, triggering a rollback from our end.
So the idea I had was to monitor the pods in the new replicaset that is being rolled out after I initiate a rolling update. This way we won't detect failing pods in the previous version as failures of the rolling update. I have found out how to find the pods within a replicaset (PS: I use powershell as my shell but hopefully the translation to bash or whatever you prefer is fairly straight forward):
kubectl get pod -n <namespace> -l <selector> -o json | ConvertFrom-Json | Where {$_.metadata.ownerReferences.name -eq <replicaset-name>}
Run Code Online (Sandbox Code Playgroud)
And I can easily find which replicaset belongs to a deployment using the same method, just querying for replicasets and filtering on their ownerReference again.
HOWEVER, a deployment has at least two replicasets during a rolling update: The new, and the old. I can see the names of those if I use "kubectl describe deployment" -- but that's not very automation-friendly without some text processing. It seems like a fragile way to do it. It would be great if I could find the same information in the json, but seems that doesn't exist.
所以,我的问题是:如何找到部署和当前/旧副本集之间的连接(最好是 JSON 格式)?是否有其他资源可以“连接”这两个副本,或者是否有一些关于副本集本身的信息我可以用来区分新副本集和旧副本集?
部署将使用注释指示副本集的当前“修订版” deployment.kubernetes.io/revision。
metadata:
annotations:
deployment.kubernetes.io/revision: "4"
Run Code Online (Sandbox Code Playgroud)
这将存在于部署和复制集中。修订版 N-1 的复制集将是“旧”复制集。
| 归档时间: |
|
| 查看次数: |
2994 次 |
| 最近记录: |