<p>I am trying to patch liveness and readiness probes parameters of a kubernetes deployment object. below is my <code>patch.yml</code>.</p>

<pre><code>--- 
spec: 
  template: 
    spec: 
      containers: 
        - 
          livenessProbe: 
            initialDelaySeconds: 280
          name: notification-service
          readinessProbe: 
            initialDelaySeconds: 220
</code></pre>

<p>Request:</p>

<pre><code>kubectl -n my-namespace --kubeconfig=my_config --context=dev patch deployment notification-service --patch "$(cat patch.yml)"
</code></pre>

<p>Response:</p>

<pre><code>kubectl : error: unable to parse "spec:   template:     spec:       containers:       - name: notification-service                 
readinessProbe:           initialDelaySeconds: 220         livenessProbe:           initialDelaySeconds: 280": yaml: mapping values are not allowed in this 
context
At line:1 char:1
+ kubectl -n my-namespace --kubeconfig=my_config --context=dev patch  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (error: unable t...in this context:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
</code></pre>

<p>Edit:
Below is the output of <code>kubectl version</code> command.</p>

<pre><code>Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e
9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"wind
ows/386"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"c27b913fddd1a6c480c229191a087698
aa92f0b1", GitTreeState:"clean", BuildDate:"2019-02-28T13:30:26Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"lin
ux/amd64"}
</code></pre>

<p><a href="https://github.com/kubernetes/kubernetes/blob/f170ef66340f6355d331ed90902574ff0532a20a/pkg/kubectl/cmd/patch.go#L143" rel="nofollow noreferrer">This</a> is the line from where this error is being thrown. To verify it, i tried creating a sample go program. Below is the code snippet. To my surprise, below code is able to process the yaml file.</p>

<pre><code>package main

import (
    "fmt"
    "io/ioutil"
    //"sigs.k8s.io/yaml" // Part of latest master k8s master vendor folder
    yaml2 "github.com/ghodss/yaml" // Part of release 1.10 k8s vendor folder
)


func check(e error) {
    if e != nil {
        panic(e)
    }
}

func main(){
    dat, err := ioutil.ReadFile("D:\\EclipseIDEJavaEEDevelopers\\Workspace\\patch.yaml")
    check(err)
    patch:=string(dat)

    patchBytes, err1 := yaml2.YAMLToJSON([]byte(patch))

    if err != nil {
         fmt.Errorf("unable to parse %q: %v", dat, err1)
    }else{
        fmt.Println("json conversion completed ",string(patchBytes))
    }


}
</code></pre>

<p>Output:</p>

<pre><code>json conversion completed  {"spec":{"template":{"spec":{"containers":[{"livenessProbe":{"initialDelaySeconds":280},"name":"notification-service","readinessProbe":{"initialDelaySeconds":220}}]}}}}
</code></pre>

Manish Bansal
<p>The issue is with the <code>powershell</code> and double quotes around command substitution.  If we add double quotes around command substitution in powershell, it removes new line from the yml due to which, kubectl is not able to convert it into json.</p>

<p>Same does work in bash. Since, I was using powershell, it did not work for me. Correct command that worked is as below.</p>

<pre><code>kubectl -n my-namespace --kubeconfig=my_config --context=dev patch deployment notification-service --patch $(cat patch.yml)
</code></pre>

<p><strong>Note:</strong> The yml has still some issues. So when I say it worked, I meant the current issue is resolved. The yml has many issues from kubernetes perspective.</p>
