考虑以下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

10-06 10:16