gpt4 book ai didi

kubernetes - 使用kubectl应用部分kubernetes list yaml

转载 作者:行者123 更新时间:2023-12-02 12:00:04 24 4
gpt4 key购买 nike

考虑以下kubernetes list (mymanifest.yml):

apiVersion: v1
kind: Pod
metadata:
name: firstpod
spec:
containers:
- image: nginx
name: nginx
---
apiVersion: v1
kind: Pod
metadata:
name: secondpod
spec:
containers:
- image: nginx
name: nginx
如果我执行 kubectl apply -f mymanifest.yml,则两个pod均已部署。
我记得有人告诉我,只能部署一个 pods 。就像是 :
kubectl apply -f mymanifest.yml secondpod
但这是行不通的。
有办法吗?
提前Thx

最佳答案

您可以向 pods 添加标签

apiVersion: v1
kind: Pod
metadata:
name: firstpod
labels:
app: firstpod
spec:
containers:
- image: nginx
name: nginx
---
apiVersion: v1
kind: Pod
metadata:
name: secondpod
labels:
app: secondpod
spec:
containers:
- image: nginx
name: nginx
应用Yaml时,请使用特定的标签进行过滤。过滤器支持 ===!=
kubectl apply -f mymanifest.yml -l app=secondpod
您还可以使用 --prune(这是Alpha功能)。
# Apply the configuration in manifest.yaml that matches label app=secondpod and delete all the other resources that are
not in the file and match label app=secondpod.
kubectl apply --prune -f mymanifest.yml -l app=secondpod

关于kubernetes - 使用kubectl应用部分kubernetes list yaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63504579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com