kubectl 修补现有容器命令

发布于 2025-01-09 01:10:35 字数 976 浏览 0 评论 0原文

我已经启动并运行了 Kubernetes 部署: (为简洁起见,省略了一些字段)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: argocd-server
  namespace: argocd
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: argocd-server
  template:
    metadata:
      creationTimestamp: null
      labels:
        app.kubernetes.io/name: argocd-server
    spec:
      containers:
        - name: argocd-server
          image: quay.io/argoproj/argocd:v2.2.5
          command:
            - argocd-server

我想为现有部署创建一个补丁,以向容器的命令添加某些参数:

            - '--insecure'
            - '--basehref'
            - /argocd

我阅读了有关 kubectl 补丁的文档> 命令 此处,但我不确定如何实际选择我想要修补的容器(按名称或索引)。
覆盖完整的 command: 列表(在补丁文件中给出 - argocd-server 行)就可以了,但我想防止给出完整的 容器:补丁文件中的规范。

I have a Kubernetes deployment up and running:
(some fields omitted for brevity)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: argocd-server
  namespace: argocd
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: argocd-server
  template:
    metadata:
      creationTimestamp: null
      labels:
        app.kubernetes.io/name: argocd-server
    spec:
      containers:
        - name: argocd-server
          image: quay.io/argoproj/argocd:v2.2.5
          command:
            - argocd-server

I would like to create a patch for the existing deployment to add certain arguements to the command of the container:

            - '--insecure'
            - '--basehref'
            - /argocd

I read the documentation on the kubectl patch command here, but I am not sure how to actually select the container (by name or index) that I would like to patch.
It would be fine to overwrite the complete command: list (giving the - argocd-server line in the patch file) but I would like to prevent giving the complete containers: spec in the patch file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吝吻 2025-01-16 01:10:35

您可以通过索引选择容器,例如:

kubectl patch deployment argocd-server -n argocd --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["argocd-server", "--insecure"]}]'

You can select the container by index, e.g.:

kubectl patch deployment argocd-server -n argocd --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["argocd-server", "--insecure"]}]'
勿忘心安 2025-01-16 01:10:35

感谢 @Blokje5 的启发,我能够构建这两个选项:

JSON 方法

内联

kubectl patch deployment argocd-server -n argocd --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["argocd-server", "--insecure", "--basehref", "/argocd"]}]'

补丁文件

patch.json

[
  {
    "op": "replace",
    "path": "/spec/template/spec/containers/0/command",
    "value": [
      "argocd-server",
      "--insecure",
      "--basehref",
      "/argocd"
    ]
  }
]
kubectl -n argocd patch deployment argocd-server --type='json' --patch-file patch.json

YAML 方法

yaml 文件

patch.yaml

---
op: replace
spec:
  template:
    spec:
      containers:
        - name: argocd-server
          command:
            - argocd-server
            - --insecure
            - --basehref
            - /argocd
kubectl -n argocd patch deployment argocd-server --patch-file patch.yaml

Thanks to the inspiration by @Blokje5 I was able to construct these two options:

JSON approach

inline

kubectl patch deployment argocd-server -n argocd --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["argocd-server", "--insecure", "--basehref", "/argocd"]}]'

with patch file

patch.json

[
  {
    "op": "replace",
    "path": "/spec/template/spec/containers/0/command",
    "value": [
      "argocd-server",
      "--insecure",
      "--basehref",
      "/argocd"
    ]
  }
]
kubectl -n argocd patch deployment argocd-server --type='json' --patch-file patch.json

YAML approach

yaml file

patch.yaml

---
op: replace
spec:
  template:
    spec:
      containers:
        - name: argocd-server
          command:
            - argocd-server
            - --insecure
            - --basehref
            - /argocd
kubectl -n argocd patch deployment argocd-server --patch-file patch.yaml
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文