</code></pre></div><p>Then, update the ingress controller so it adopts the static IP of the Service by passing the <code>--publish-service</code> flag (the example yaml used in the next step already has it set to "ingress-nginx-lb").</p><divclass=highlight><pre><span></span><code><spanclass=gp>$ </span>kubectl<spanclass=w></span>create<spanclass=w></span>-f<spanclass=w></span>ingress-nginx-controller.yaml
</code></pre></div><h2id=assigning-the-ip-to-an-ingress>Assigning the IP to an Ingress<aclass=headerlinkhref=#assigning-the-ip-to-an-ingresstitle="Permanent link"> ¶</a></h2><p>From here on every Ingress created with the <code>ingress.class</code> annotation set to <code>nginx</code> will get the IP allocated in the previous step.</p><divclass=highlight><pre><span></span><code><spanclass=gp>$ </span>kubectl<spanclass=w></span>create<spanclass=w></span>-f<spanclass=w></span>ingress-nginx.yaml
</code></pre></div><h2id=retaining-the-ip>Retaining the IP<aclass=headerlinkhref=#retaining-the-iptitle="Permanent link"> ¶</a></h2><p>You can test retention by deleting the Ingress:</p><divclass=highlight><pre><span></span><code><spanclass=gp>$ </span>kubectl<spanclass=w></span>delete<spanclass=w></span>ing<spanclass=w></span>ingress-nginx
</code></pre></div><blockquote><p>Note that unlike the GCE Ingress, the same loadbalancer IP is shared amongst all Ingresses, because all requests are proxied through the same set of nginx controllers.</p></blockquote><h2id=promote-ephemeral-to-static-ip>Promote ephemeral to static IP<aclass=headerlinkhref=#promote-ephemeral-to-static-iptitle="Permanent link"> ¶</a></h2><p>To promote the allocated IP to static, you can update the Service manifest:</p><divclass=highlight><pre><span></span><code><spanclass=gp>$ </span>kubectl<spanclass=w></span>patch<spanclass=w></span>svc<spanclass=w></span>ingress-nginx-lb<spanclass=w></span>-p<spanclass=w></span><spanclass=s1>'{"spec": {"loadBalancerIP": "104.154.109.191"}}'</span>
</code></pre></div><p>... and promote the IP to static (promotion works differently for cloudproviders, provided example is for GKE/GCE):</p><divclass=highlight><pre><span></span><code><spanclass=gp>$ </span>gcloud<spanclass=w></span>compute<spanclass=w></span>addresses<spanclass=w></span>create<spanclass=w></span>ingress-nginx-lb<spanclass=w></span>--addresses<spanclass=w></span><spanclass=m>104</span>.154.109.191<spanclass=w></span>--region<spanclass=w></span>us-central1
</code></pre></div><p>Now even if the Service is deleted, the IP will persist, so you can recreate the Service with <code>spec.loadBalancerIP</code> set to <code>104.154.109.191</code>.</p></article></div></div></main><footerclass=md-footer><divclass="md-footer-meta md-typeset"><divclass="md-footer-meta__inner md-grid"><divclass=md-copyright> Made with <ahref=https://squidfunk.github.io/mkdocs-material/target=_blankrel=noopener> Material for MkDocs </a></div></div></div></footer></div><divclass=md-dialogdata-md-component=dialog><divclass="md-dialog__inner md-typeset"></div></div><scriptid=__configtype=application/json>{"base":"../..","features":["navigation.tabs","navigation.tabs.sticky","navigation.instant","navigation.sections"],"search":"../../assets/javascripts/workers/search.f886a092.min.js","translations":{"clipboard.copied":"Copied to clipboard","clipboard.copy":"Copy to clipboard","search.result.more.one":"1 more on this page","search.result.more.other":"# more on this page","search.result.none":"No matching documents","search.result.one":"1 matching document","search.result.other":"# matching documents","search.result.placeholder":"Type to start searching","search.result.term.missing":"Missing","select.version":"Select version"}}</script><scriptsrc=../../assets/javascripts/bundle.aecac24b.min.js></script></body></html>