Nitisha
Nitisha

Reputation: 61

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

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!!

Upvotes: 6

Views: 15682

Answers (4)

Joonu Thomas
Joonu Thomas

Reputation: 318

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;\"
}

Upvotes: 0

Tohid Makari
Tohid Makari

Reputation: 2494

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}}'

Upvotes: 17

najx
najx

Reputation: 87

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\"}}]}}}}

Upvotes: 2

Mushroomator
Mushroomator

Reputation: 9258

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.

Upvotes: 2

Related Questions