<p>We have a kubernetes <code>Ingress</code> object defined. All the ingress rules are not available when defining object for the first time, hence we would like to append rules to it on the fly when configuring respective services to use with it.</p>
<p>Example:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    alb.ingress.kubernetes.io/certificate-arn: ${acm_arn}
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: instance
    kubernetes.io/ingress.class: alb
  name: ${ingress_name}
  namespace: ${namespace}
spec:
  rules:
    - host: api.${region}.infra.${hosted_zone}
      http:
        paths:
          - backend:
              service:
               name: istio-ingressgateway
               port:
                number: 80
            path: /*
            pathType: Prefix
    - http:
        paths:
          - backend:
              service:
               name: nginx-ingress-controller
               port:
                number: 80
            path: /*
            pathType: Prefix

</code></pre>
<p>The above object is created in the beginning. Now, we would like to append a third rule to it at later point in time.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
  name: ${ingress_name}
  namespace: ${namespace}
spec:
  rules:
    - host: api.${region}.${some_dynamic_variable}.${hosted_zone}
      http:
        paths:
          - backend:
              service:
               name: istio-ingressgateway
               port:
                number: 80
            path: /*
            pathType: Prefix
</code></pre>
<p>I could have used <code>kubectl patch</code> but because the merge strategy is not specified in the <a href="https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json" rel="nofollow noreferrer">api docs</a>, I understand it follows the merge strategy <code>replace</code> which is not what I intend to do.</p>
<p>What is the best available option to get this issue resolved?</p>

Mukund Jalan
<p>There is a <code>kubectl</code> plugin called <a href="https://github.com/pragaonj/ingress-rule-updater" rel="nofollow noreferrer"><code>ingress-rule</code></a>. It allows you to configure an Ingress on the command line.
The plugin is available via <a href="https://krew.sigs.k8s.io/" rel="nofollow noreferrer"><code>krew</code></a>. If you have <code>krew</code> installed simply install the plugin with:</p>
<pre><code>kubectl krew install ingress-rule
</code></pre>
<p>Add a new rule to a existing Ingress:</p>
<pre><code>kubectl ingress-rule -n $NAMESPACE set $INGRESSNAME --service $SERVICENAME --port 80 --host $HOST
</code></pre>
<p>Delete the previously added rule:</p>
<pre><code>kubectl ingress-rule -n $NAMESPACE delete $INGRESSNAME --service $SERVICENAME
</code></pre>
