我想驗證具有 Pod 和 NodeAffinity ( AntiAffinity) 的部署是根據內部準則配置的。
是否有可能使用 kubectl 獲取部署(或 Pod)并將結果限制為配置了這種親和性的物件?
我玩過 jsonpath 輸出,但到目前為止還沒有成功。
uj5u.com熱心網友回復:
希望您享受您的 Kubernetes 之旅!
如果您需要使用關聯(尤其是preferredDuringSchedulingIgnoredDuringExecution(下面的解釋))并且只想“找到”實際具有關聯的部署,您可以使用它:
? k get deploy -o custom-columns=NAME:".metadata.name",AFFINITIES:".spec.template.spec.affinity"
NAME AFFINITIES
nginx-deployment <none>
nginx-deployment-vanilla <none>
nginx-deployment-with-affinities map[nodeAffinity:map[preferredDuringSchedulingIgnoredDuringExecution:[map[preference:map[matchExpressions:[map[key:test-affinities1 operator:In values:[test1]]]] weight:1]] requiredDuringSchedulingIgnoredDuringExecution:map[nodeSelectorTerms:[map[matchExpressions:[map[key:test-affinities operator:In values:[test]]]]]]]]
每個<none>模式都表明部署中沒有關聯。
但是,對于關聯性,如果您只想獲取具有關聯性的部署而不獲取沒有關聯性的部署,請使用以下命令:
? k get deploy -o custom-columns=NAME:".metadata.name",AFFINITIES:".spec.template.spec.affinity" | grep -v "<none>"
NAME AFFINITIES
nginx-deployment-with-affinities map[nodeAffinity:map[preferredDuringSchedulingIgnoredDuringExecution:[map[preference:map[matchExpressions:[map[key:test-affinities1 operator:In values:[test1]]]] weight:1]] requiredDuringSchedulingIgnoredDuringExecution:map[nodeSelectorTerms:[map[matchExpressions:[map[key:test-affinities operator:In values:[test]]]]]]]]
如果您只想要具有相似性的部署的名稱,請考慮使用這個小腳本:
? k get deploy -o custom-columns=NAME:".metadata.name",AFFINITIES:".spec.template.spec.affinity" --no-headers | grep -v "<none>" | awk '{print $1}'
nginx-deployment-with-affinities
但是,不要忘記這nodeSelector是將 Pod 約束到具有特定標簽的節點的最簡單方法。(更多資訊:https ://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity )。還要記住(根據相同的鏈接)requiredDuringSchedulingIgnoredDuringExecution節點 Affinity 函式的型別類似于 nodeSelector,但具有更具表現力的語法!preferredDuringSchedulingIgnoredDuringExecution因此,如果您在處理親和力時不需要考慮使用 nodeSelector !
在閱讀了上面的鏈接之后,如果你想處理 nodeSelector ,你可以使用我之前使用的相同機制:
? k get deploy -o custom-columns=NAME:".metadata.name",NODE_SELECTOR:".spec.template.spec.nodeSelector"
NAME NODE_SELECTOR
nginx-deployment map[test-affinities:test]
nginx-deployment-vanilla <none>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/480761.html
上一篇:如何將運行python程式的pod與另一個運行資料庫的pod連接起來
下一篇:我的豆莢不斷重啟,我不知道為什么
