Error from server (BadRequest): invalid character 's' looking for beginning of object key string
Asked Answered
R

4

6

I am new to k8s and need some help, plz.

I want to make a change in a pod's deployment configuration and change readOnlyRootFilesystem to false.

This is what I am trying to do, but it doesn't seem to work. Plz suggest what's wrong:

kubectl patch deployment eric-ran-rdm-singlepod -n vdu -o yaml -p {"spec":{"template":{"spec":{"containers":[{"name":"eric-ran-rdm-infra":{"securityContext":[{"readOnlyRootFilesystem":"true"}]}}]}}}}

enter image description here

Thanks very much!!

Reach answered 21/3, 2022 at 16:10 Comment(3)
Try adding single quote '{"spec":{"template":{"spec":{"containers":[{"name":"eric-ran-rdm-infra":{"securityContext":[{"readOnlyRootFilesystem":"true"}]}}]}}}}' around the patch.Bitolj
You can also update the YAML file and then use kubectl apply -f <your file>.yaml. It will automatically generate and apply the patch.Bitolj
You are not supplying valid JSON. Use jsonlint.com to check your JSON.Muumuu
C
13

In windows, you need to add before double quote in the command with a backslash.

kubectl patch cronjob/zoo-pc-route-cost-job -p '{\"spec\": {\"suspend\": false}}'
Cushing answered 17/11, 2023 at 15:55 Comment(0)
M
2

Your JSON is invalid. You need to make sure you are providing valid JSON and it should be in the correct structure as defined by the k8s API as well. You can use jsonlint.com.

{
    "spec": {
        "template": {
            "spec": {
                "containers": [
                    {
                        "name": "eric-ran-rdm-infra",
                        "securityContext": {
                            "readOnlyRootFilesystem": "true"
                        }
                    }
                ]
            }
        }
    }
}

Note: I have only checked the syntax here and not checked/ tested the structure against the k8s API of this JSON here, but I think it should be right, please correct me if I am wrong.

It might be easier to specify a deployment in a .yaml file and just apply that using kubectl apply -f my_deployment.yaml.

Muumuu answered 21/3, 2022 at 16:29 Comment(0)
H
2

First, you should fix your JSON syntax issue as suggested by @Mushroomator

{
    "spec": {
        "template": {
            "spec": {
                "containers": [
                    {
                        "name": "eric-ran-rdm-infra",
                        "securityContext": {
                            "readOnlyRootFilesystem": "true"
                        }
                    }
                ]
            }
        }
    }
}

Then, JSON should also be specified with escape char before double quotes.

Following this way:

kubectl patch deployment eric-ran-rdm-singlepod -n vdu -o yaml -p {\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\": \"eric-ran-rdm-infra\",\"securityContext\":{\"readOnlyRootFilesystem\":\"true\"}}]}}}}
Hypervitaminosis answered 20/7, 2022 at 15:0 Comment(0)
T
0

I got the same error while trying to POST an SQL query as payload to a REST endpoint. My payload was something like

{
  "sql": "SELECT col1, col2 from TableA;"
}

It got resolved when I escaped the quotes using backslashes

{
  \"sql\": \"SELECT col1, col2 from TableA;\"
}
Tola answered 18/6 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.