kubectl 修补现有容器命令

kubectl patch existing container command

我已经部署了 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

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

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

我阅读了有关 kubectl patch 命令 here 的文档,但我不确定如何 select 我想要修补的容器(按名称或索引) .
覆盖完整的 command: 列表(在补丁文件中给出 - argocd-server 行)会很好,但我想防止在补丁文件中给出完整的 containers: 规范。

您可以 select 容器索引,例如:

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

感谢@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