<p>As I can see the below page, I can set up two or three hosts in one Ingress.
<a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting" rel="noreferrer">https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting</a></p>

<p>But how do I add a new host to existing ingress?
I tried the commands like apply or patch, but it didn't work.</p>

<p>Is there anyone who know this solution?</p>

<pre><code>kubectl patch -f sample-ingress.yml -p ' 
  {"metadata": {"name": "sample-ingress"}, "spec": [{
    "host": "39500000.sample.com",
    "http": {"paths": [{
      "backend": {"serviceName": "39500000", "servicePort": 8080}
    }]
  }}]
}'
The Ingress "sample-ingress" is invalid: spec.backend.serviceName: Required value
</code></pre>

<p>I personally prefer to use <strong>PATCH</strong> as my preferred approach to add an new host to an existing kubernetes ingress.</p>

<p>The command is going to look like this:
<code>kubectl patch ingress my-ingress --type json --patch "$(cat patch.json)"</code></p>

<p>where patch.json is</p>

<pre><code>[
    {
        "op" : "add" ,
        "path" : "/spec/rules/-" ,
        "value" : {
            "host": "evil.facebook.com",
            "http": {
                "paths": [
                    {
                        "backend": {
                            "serviceName": "tracker-app",
                            "servicePort": 80
                        }
                    }
                ]
            }
        }
    }
]
</code></pre>

<p>A few notes:
 - my-ingress is the name of the deployed ingress in the cluster
 - one can just paste the json instead of using this trick "$(cat patch.json)"</p>

<p>Also, the main thing about this solution is that it <strong>leverages kubernetes own capabilities</strong> to merge json according to <a href="http://erosb.github.io/post/json-patch-vs-merge-patch/" rel="noreferrer">these rules</a>.</p>

<p>More information patching from an official source can be <a href="https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/" rel="noreferrer">found here</a>.</p>
