问题描述
考虑以下kubernetes清单(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均已部署。
我记得有人告诉我,只能部署一个吊舱。像这样的东西:
kubectl apply -f mymanifest.yml secondpod
但是它不起作用。 有办法吗?
提前谢谢
解决方法
您可以在吊舱中添加标签
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