Patching kubernetes dashboard

4/11/2019

I'm trying to modify kubernetes-dashboard deployment with patch command. I need to add "- --enable-skip-login" arg to containers section with one command. Something like that:

kubectl -n kube-system patch deployment kubernetes-dashboard --patch '{"spec":{"template":{"spec":{"containers":{"- args":{"- --enable-skip-login"}}}}}}'

But this doesn't work and I need right syntax to add this arg in the deployment yaml.

-- lexadler
kubernetes

2 Answers

4/11/2019

containers and args are arrays so in JSON the representation would be this:

{
  "spec": {
    "template": {
      "spec": {
        "containers": [
          { 
            "name", "yourcontainername",
            "args": [
              "--enable-skip-login"
            ]
          }
        ]
      }
    }
  }
}

So, you can try:

$ kubectl -n kube-system patch deployment kubernetes-dashboard --patch \
'{"spec":{"template":{"spec":{"containers":[{"name": "yourcontainername","args": ["--enable-skip-login"]}]}}}}'

Note that you need "name" since it's a merge key. More info here

(answer was corrected in section):

"name",  "yourcontainername" 
-- Rico
Source: StackOverflow

4/12/2019

Finally I've got what I want by using patch with adding new element to an array:

kubectl -n kube-system patch deploy kubernetes-dashboard --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--enable-skip-login"}]'

The previous answer will be useful if there was no args or if you transfer all args in array like this:

kubectl -n kube-system patch deployment kubernetes-dashboard --patch \
'{"spec":{"template":{"spec":{"containers":[{"name": "kubernetes-dashboard","args": ["--auto-generate-certificates", "--enable-skip-login"]}]}}}}'
-- lexadler
Source: StackOverflow