【问题标题】:In Kubernetes How to patch a container within a deployment在 Kubernetes 中如何修补部署中的容器
【发布时间】:2017-12-29 05:28:48
【问题描述】:

我想使用补丁 API 将卷添加到容器(不适用)

此补丁不起作用:

spec:
  template:
    spec:
      volumes:
        - name: cep-debug-dir
          persistentVolumeClaim:
           claimName: cep-pvc-debug
      containers:
        name: cep
        - mountPath: /debug
          name: cep-debug-dir
        volumeMounts:
          - mountPath: /debug
            name: cep-debug-dir

我的用例是扩展部署 yaml,添加已安装的卷以进行开发,并且通常具有多态部署,而无需重复 yaml 代码并且必须维护两个文件中的更改。

附言 我正在使用配置映射,如果我可以使用 if 有条件地挂载卷,那就太酷了。

【问题讨论】:

    标签: kubernetes yaml


    【解决方案1】:

    我打印了部署 json 并使用/编辑了 json 格式的字段,并且补丁正常工作 在终端中

    kubectl patch deploy cep --patch "$(cat cep-deploy-patch.yaml)"
    

    文件:

    {
        "spec": {
            "template": {
                "spec": {
                    "containers": [{
                        "name": "cep",
                        "volumeMounts": [{
                            "mountPath": "/debug",
                            "name": "cep-debug-dir"
                        }]
                    }],
                    "volumes": [{
                        "name": "cep-debug-dir",
                        "persistentVolumeClaim": {
                            "claimName": "cep-pvc-debug"
                        }
                    }]
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-22
      • 2018-11-18
      • 2019-05-22
      • 2020-05-22
      • 2022-12-17
      • 2020-11-16
      • 1970-01-01
      • 2022-08-16
      • 1970-01-01
      相关资源
      最近更新 更多