使用 kubectl 应用部分 kubernetes manifest yaml
Apply part of kubernetes manifest yaml using kubectl
考虑以下 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
两个 pods 都已部署。
我记得有人告诉我,可以只部署一个 pod。像 :
kubectl apply -f mymanifest.yml secondpod
但是没用。
有办法吗?
提前致谢
您可以将标签添加到 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 清单 (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
两个 pods 都已部署。
我记得有人告诉我,可以只部署一个 pod。像 :
kubectl apply -f mymanifest.yml secondpod
但是没用。 有办法吗?
提前致谢
您可以将标签添加到 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