0

i'm working with Kubernetes and Jenkins-x, i need to create a devpod with customized property. In particular i need a timeoutSeconds for the livenessProbe differebt from the default one. I dont know how to customize this attribute before the pod is created so i'm trying to update it once it's running. I tried with

kubectl edit pod/<pod_name>

but it told me i cant update that property.

Do you have suggestions on how i can do this?

Thank you.

IlBosco
  • 1
  • 1
  • 4

2 Answers2

1

Although this may not be something you really want to do in production but you can follow these steps.

  1. Get the yaml from the cluster kubectl get pod podname -o yaml --export > pod.yaml

  2. Delete the running pod kubectl deplete pod podname

  3. Edit the pod.yaml and apply it to the cluster.

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
  • i dont have control on the process tha yaml and the process that apply the yaml. Do you know a way to update a once it's applied? – IlBosco May 14 '20 at 15:24
  • is it okay if you could get the yaml from the cluster and save it and edit and reapply? – Arghya Sadhu May 14 '20 at 15:25
  • i did this with kubectl edit pod/ , this open the yaml and lets you edit, but when you save and close it gave me this error "Pod "laptop-n5oengpg-luca-nodejs2" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`, `spec.initContainers[*].image`, `..... ". Tried the same from Google cloud UI editing the yaml but i have the same error – IlBosco May 14 '20 at 15:29
  • kubectl edit will not let you edit that..you will have to save in a yaml and edit it and delete the old pod and re apply the edited yaml – Arghya Sadhu May 14 '20 at 15:30
  • yes i tried to delete and apply a new yaml and it woks but in this way a lose pointers to other pods that the original jenkins-x create devpod command create. So i'm trying to update it without destroy – IlBosco May 14 '20 at 15:40
0

You can use kubectl --overrides flag. Something similar to this,

kubectl run busybox --image=busybox --restart=Never --overrides='
      {
         "apiVersion": "v1",
         "kind": "Pod",
         "metadata": {
            "labels": {
               "test": "liveness"
            },
            "name": "liveness-exec"
         },
         "spec": {
            "containers": [
               {
                  "name": "liveness",
                  "image": "k8s.gcr.io/busybox",
                  "livenessProbe": {
                     "exec": {
                        "command": [
                           "cat",
                           "/tmp/healthy"
                        ]
                     },
                     "initialDelaySeconds": 5,
                     "periodSeconds": 5
                  }
               }
            ]
         }
      }
      '
hariK
  • 2,722
  • 13
  • 18