【问题标题】:Apply part of kubernetes manifest yaml using kubectl使用 kubectl 应用部分 Kubernetes 清单 yaml
【发布时间】:2020-12-09 18:16:01
【问题描述】:

考虑以下 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 都已部署。 我记得有人告诉我,可以只部署一个 pod。类似的东西:

kubectl apply -f mymanifest.yml secondpod

但它不起作用。 有办法吗?

提前谢谢

【问题讨论】:

    标签: kubernetes yaml kubectl


    【解决方案1】:

    您可以为 pod 添加标签

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-15
      • 2016-05-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      相关资源
      最近更新 更多