ingress-nginx-helm/deploy/baremetal/index.html

115 lines
55 KiB
HTML
Raw Permalink Normal View History

2025-01-22 12:59:16 +00:00
<!doctype html><html lang=en class=no-js> <head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link href=https://kubernetes.github.io/ingress-nginx/deploy/baremetal/ rel=canonical><link href=../ rel=prev><link href=../rbac/ rel=next><link rel=icon href=../../assets/images/favicon.png><meta name=generator content="mkdocs-1.5.3, mkdocs-material-9.4.5"><title>Bare-metal considerations - Ingress-Nginx Controller</title><link rel=stylesheet href=../../assets/stylesheets/main.6a10b989.min.css><link rel=stylesheet href=../../assets/stylesheets/palette.356b1318.min.css><link rel=preconnect href=https://fonts.gstatic.com crossorigin><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback"><style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style><link rel=stylesheet href=../../extra.css><script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script></head> <body dir=ltr data-md-color-scheme=default data-md-color-primary=teal data-md-color-accent=green> <input class=md-toggle data-md-toggle=drawer type=checkbox id=__drawer autocomplete=off> <input class=md-toggle data-md-toggle=search type=checkbox id=__search autocomplete=off> <label class=md-overlay for=__drawer></label> <div data-md-component=skip> <a href=#bare-metal-considerations class=md-skip> Skip to content </a> </div> <div data-md-component=announce> </div> <header class="md-header md-header--shadow md-header--lifted" data-md-component=header> <nav class="md-header__inner md-grid" aria-label=Header> <a href=../.. title="Ingress-Nginx Controller" class="md-header__button md-logo" aria-label="Ingress-Nginx Controller" data-md-component=logo> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg> </a> <label class="md-header__button md-icon" for=__drawer> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg> </label> <div class=md-header__title data-md-component=header-title> <div class=md-header__ellipsis> <div class=md-header__topic> <span class=md-ellipsis> Ingress-Nginx Controller </span> </div> <div class=md-header__topic data-md-component=header-topic> <span class=md-ellipsis> Bare-metal considerations </span> </div> </div> </div> <label class="md-header__button md-icon" for=__search> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg> </label> <div class=md-search data-md-component=search role=dialog> <label class=md-search__overlay for=__search></label> <div class=md-search__inner role=search> <form class=md-search__form name=search> <input type=text class=md-search__input name=query aria-label=Search placeholder=Search autocapitalize=off autocorrect=off autocomplete=off spellcheck=false data-md-component=search-query required> <label class="md-search__icon md-icon" for=__search> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg> </label> <nav class=md-search__options aria-label=Search> <button type=reset class="md-search__ic
2021-01-11 15:59:14 +00:00
<span class=go>NAME STATUS ROLES EXTERNAL-IP</span>
<span class=go>host-1 Ready master 203.0.113.1</span>
<span class=go>host-2 Ready node 203.0.113.2</span>
<span class=go>host-3 Ready node 203.0.113.3</span>
2022-07-13 09:54:46 +00:00
</code></pre></div> <p>After creating the following objects, MetalLB takes ownership of one of the IP addresses in the pool and updates the <em>loadBalancer</em> IP field of the <code>ingress-nginx</code> Service accordingly.</p> <div class=highlight><pre><span></span><code><span class=nn>---</span>
2023-10-12 19:31:18 +00:00
<span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">metallb.io/v1beta1</span>
<span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">IPAddressPool</span>
2021-01-11 15:59:14 +00:00
<span class=nt>metadata</span><span class=p>:</span>
2023-10-12 19:31:18 +00:00
<span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">default</span>
<span class=w> </span><span class=nt>namespace</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">metallb-system</span>
2022-07-13 09:54:46 +00:00
<span class=nt>spec</span><span class=p>:</span>
2023-10-12 19:31:18 +00:00
<span class=w> </span><span class=nt>addresses</span><span class=p>:</span>
<span class=w> </span><span class="p p-Indicator">-</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">203.0.113.10-203.0.113.15</span>
<span class=w> </span><span class=nt>autoAssign</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">true</span>
2022-07-13 09:54:46 +00:00
<span class=nn>---</span>
2023-10-12 19:31:18 +00:00
<span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">metallb.io/v1beta1</span>
<span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">L2Advertisement</span>
2022-07-13 09:54:46 +00:00
<span class=nt>metadata</span><span class=p>:</span>
2023-10-12 19:31:18 +00:00
<span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">default</span>
<span class=w> </span><span class=nt>namespace</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">metallb-system</span>
2022-07-13 09:54:46 +00:00
<span class=nt>spec</span><span class=p>:</span>
2023-10-12 19:31:18 +00:00
<span class=w> </span><span class=nt>ipAddressPools</span><span class=p>:</span>
<span class=w> </span><span class="p p-Indicator">-</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">default</span>
</code></pre></div> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>-n<span class=w> </span>ingress-nginx<span class=w> </span>get<span class=w> </span>svc
2021-01-11 15:59:14 +00:00
<span class=go>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)</span>
<span class=go>default-http-backend ClusterIP 10.0.64.249 &lt;none&gt; 80/TCP</span>
<span class=go>ingress-nginx LoadBalancer 10.0.220.217 203.0.113.10 80:30100/TCP,443:30101/TCP</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> </div> <p>As soon as MetalLB sets the external IP address of the <code>ingress-nginx</code> LoadBalancer Service, the corresponding entries are created in the iptables NAT table and the node with the selected IP address starts responding to HTTP requests on the ports configured in the LoadBalancer Service:</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>curl<span class=w> </span>-D-<span class=w> </span>http://203.0.113.10<span class=w> </span>-H<span class=w> </span><span class=s1>&#39;Host: myapp.example.com&#39;</span>
2021-01-11 15:59:14 +00:00
<span class=go>HTTP/1.1 200 OK</span>
<span class=go>Server: nginx/1.15.2</span>
2025-01-22 12:59:16 +00:00
</code></pre></div> <div class="admonition tip"> <p class=admonition-title>Tip</p> <p>In order to preserve the source IP address in HTTP requests sent to NGINX, it is necessary to use the <code>Local</code> traffic policy. Traffic policies are described in more details in <a href=https://metallb.universe.tf/usage/#traffic-policies>Traffic policies</a> as well as in the next section.</p> </div> <h2 id=over-a-nodeport-service>Over a NodePort Service<a class=headerlink href=#over-a-nodeport-service title="Permanent link"></a></h2> <p>Due to its simplicity, this is the setup a user will deploy by default when following the steps described in the <a href=../#bare-metal>installation guide</a>.</p> <div class="admonition info"> <p class=admonition-title>Info</p> <p>A Service of type <code>NodePort</code> exposes, via the <code>kube-proxy</code> component, the <strong>same unprivileged</strong> port (default: 30000-32767) on every Kubernetes node, masters included. For more information, see <a href=https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport>Services</a>.</p> </div> <p>In this configuration, the NGINX container remains isolated from the host network. As a result, it can safely bind to any port, including the standard HTTP ports 80 and 443. However, due to the container namespace isolation, a client located outside the cluster network (e.g. on the public internet) is not able to access Ingress hosts directly on ports 80 and 443. Instead, the external client must append the NodePort allocated to the <code>ingress-nginx</code> Service to HTTP requests.</p> <p><img alt="NodePort request flow" src=../../images/baremetal/nodeport.jpg></p> <p>You can <strong>customize the exposed node port numbers</strong> by setting the <code>controller.service.nodePorts.*</code> Helm values, but they still have to be in the 30000-32767 range.</p> <div class="admonition example"> <p class=admonition-title>Example</p> <p>Given the NodePort <code>30100</code> allocated to the <code>ingress-nginx</code> Service</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>-n<span class=w> </span>ingress-nginx<span class=w> </span>get<span class=w> </span>svc
2021-01-11 15:59:14 +00:00
<span class=go>NAME TYPE CLUSTER-IP PORT(S)</span>
<span class=go>default-http-backend ClusterIP 10.0.64.249 80/TCP</span>
<span class=go>ingress-nginx NodePort 10.0.220.217 80:30100/TCP,443:30101/TCP</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> <p>and a Kubernetes node with the public IP address <code>203.0.113.2</code> (the external IP is added as an example, in most bare-metal environments this value is &lt;None&gt;)</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>get<span class=w> </span>node
2021-01-11 15:59:14 +00:00
<span class=go>NAME STATUS ROLES EXTERNAL-IP</span>
<span class=go>host-1 Ready master 203.0.113.1</span>
<span class=go>host-2 Ready node 203.0.113.2</span>
<span class=go>host-3 Ready node 203.0.113.3</span>
2025-01-22 12:59:16 +00:00
</code></pre></div> <p>a client would reach an Ingress with <code>host: myapp.example.com</code> at <code>http://myapp.example.com:30100</code>, where the myapp.example.com subdomain resolves to the 203.0.113.2 IP address.</p> </div> <div class="admonition danger"> <p class=admonition-title>Impact on the host system</p> <p>While it may sound tempting to reconfigure the NodePort range using the <code>--service-node-port-range</code> API server flag to include unprivileged ports and be able to expose ports 80 and 443, doing so may result in unexpected issues including (but not limited to) the use of ports otherwise reserved to system daemons and the necessity to grant <code>kube-proxy</code> privileges it may otherwise not require.</p> <p>This practice is therefore <strong>discouraged</strong>. See the other approaches proposed in this page for alternatives.</p> </div> <p>This approach has a few other limitations one ought to be aware of:</p> <h3 id=source-ip-address>Source IP address<a class=headerlink href=#source-ip-address title="Permanent link"></a></h3> <p>Services of type NodePort perform <a href=https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-type-nodeport>source address translation</a> by default. This means the source IP of a HTTP request is always <strong>the IP address of the Kubernetes node that received the request</strong> from the perspective of NGINX.</p> <p>The recommended way to preserve the source IP in a NodePort setup is to set the value of the <code>externalTrafficPolicy</code> field of the <code>ingress-nginx</code> Service spec to <code>Local</code> (<a href=https://github.com/kubernetes/ingress-nginx/blob/ingress-nginx-3.15.2/deploy/static/provider/aws/deploy.yaml#L290>example</a>).</p> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>This setting effectively <strong>drops packets</strong> sent to Kubernetes nodes which are not running any instance of the NGINX Ingress controller. Consider <a href=https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ >assigning NGINX Pods to specific nodes</a> in order to control on what nodes the Ingress-Nginx Controller should be scheduled or not scheduled.</p> </div> <div class="admonition example"> <p class=admonition-title>Example</p> <p>In a Kubernetes cluster composed of 3 nodes (the external IP is added as an example, in most bare-metal environments this value is &lt;None&gt;)</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>get<span class=w> </span>node
2021-01-11 15:59:14 +00:00
<span class=go>NAME STATUS ROLES EXTERNAL-IP</span>
<span class=go>host-1 Ready master 203.0.113.1</span>
<span class=go>host-2 Ready node 203.0.113.2</span>
<span class=go>host-3 Ready node 203.0.113.3</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> <p>with a <code>ingress-nginx-controller</code> Deployment composed of 2 replicas</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>-n<span class=w> </span>ingress-nginx<span class=w> </span>get<span class=w> </span>pod<span class=w> </span>-o<span class=w> </span>wide
2021-01-11 15:59:14 +00:00
<span class=go>NAME READY STATUS IP NODE</span>
<span class=go>default-http-backend-7c5bc89cc9-p86md 1/1 Running 172.17.1.1 host-2</span>
<span class=go>ingress-nginx-controller-cf9ff8c96-8vvf8 1/1 Running 172.17.0.3 host-3</span>
<span class=go>ingress-nginx-controller-cf9ff8c96-pxsds 1/1 Running 172.17.1.4 host-2</span>
2025-01-22 12:59:16 +00:00
</code></pre></div> <p>Requests sent to <code>host-2</code> and <code>host-3</code> would be forwarded to NGINX and original client's IP would be preserved, while requests to <code>host-1</code> would get dropped because there is no NGINX replica running on that node.</p> </div> <p>Other ways to preserve the source IP in a NodePort setup are described here: <a href=https://kubernetes.github.io/ingress-nginx/user-guide/miscellaneous/#source-ip-address>Source IP address</a>.</p> <h3 id=ingress-status>Ingress status<a class=headerlink href=#ingress-status title="Permanent link"></a></h3> <p>Because NodePort Services do not get a LoadBalancerIP assigned by definition, the Ingress-Nginx Controller <strong>does not update the status of Ingress objects it manages</strong>.</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>get<span class=w> </span>ingress
2021-01-11 15:59:14 +00:00
<span class=go>NAME HOSTS ADDRESS PORTS</span>
<span class=go>test-ingress myapp.example.com 80</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> <p>Despite the fact there is no load balancer providing a public IP address to the Ingress-Nginx Controller, it is possible to force the status update of all managed Ingress objects by setting the <code>externalIPs</code> field of the <code>ingress-nginx</code> Service.</p> <div class="admonition warning"> <p class=admonition-title>Warning</p> <p>There is more to setting <code>externalIPs</code> than just enabling the Ingress-Nginx Controller to update the status of Ingress objects. Please read about this option in the <a href=https://kubernetes.io/docs/concepts/services-networking/service/#external-ips>Services</a> page of official Kubernetes documentation as well as the section about <a href=#external-ips>External IPs</a> in this document for more information.</p> </div> <div class="admonition example"> <p class=admonition-title>Example</p> <p>Given the following 3-node Kubernetes cluster (the external IP is added as an example, in most bare-metal environments this value is &lt;None&gt;)</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>get<span class=w> </span>node
2021-01-11 15:59:14 +00:00
<span class=go>NAME STATUS ROLES EXTERNAL-IP</span>
<span class=go>host-1 Ready master 203.0.113.1</span>
<span class=go>host-2 Ready node 203.0.113.2</span>
<span class=go>host-3 Ready node 203.0.113.3</span>
</code></pre></div> <p>one could edit the <code>ingress-nginx</code> Service and add the following field to the object spec</p> <div class=highlight><pre><span></span><code><span class=nt>spec</span><span class=p>:</span>
2023-10-12 19:31:18 +00:00
<span class=w> </span><span class=nt>externalIPs</span><span class=p>:</span>
<span class=w> </span><span class="p p-Indicator">-</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">203.0.113.1</span>
<span class=w> </span><span class="p p-Indicator">-</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">203.0.113.2</span>
<span class=w> </span><span class="p p-Indicator">-</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">203.0.113.3</span>
</code></pre></div> <p>which would in turn be reflected on Ingress objects as follows:</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>get<span class=w> </span>ingress<span class=w> </span>-o<span class=w> </span>wide
2021-01-11 15:59:14 +00:00
<span class=go>NAME HOSTS ADDRESS PORTS</span>
<span class=go>test-ingress myapp.example.com 203.0.113.1,203.0.113.2,203.0.113.3 80</span>
2025-01-22 12:59:16 +00:00
</code></pre></div> </div> <h3 id=redirects>Redirects<a class=headerlink href=#redirects title="Permanent link"></a></h3> <p>As NGINX is <strong>not aware of the port translation operated by the NodePort Service</strong>, backend applications are responsible for generating redirect URLs that take into account the URL used by external clients, including the NodePort.</p> <div class="admonition example"> <p class=admonition-title>Example</p> <p>Redirects generated by NGINX, for instance HTTP to HTTPS or <code>domain</code> to <code>www.domain</code>, are generated without NodePort:</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>curl<span class=w> </span>-D-<span class=w> </span>http://myapp.example.com:30100<span class=sb>`</span>
2021-01-11 15:59:14 +00:00
<span class=go>HTTP/1.1 308 Permanent Redirect</span>
<span class=go>Server: nginx/1.15.2</span>
<span class=go>Location: https://myapp.example.com/ #-&gt; missing NodePort in HTTPS redirect</span>
2023-05-05 16:32:16 +00:00
</code></pre></div> </div> <h2 id=via-the-host-network>Via the host network<a class=headerlink href=#via-the-host-network title="Permanent link"></a></h2> <p>In a setup where there is no external load balancer available but using NodePorts is not an option, one can configure <code>ingress-nginx</code> Pods to use the network of the host they run on instead of a dedicated network namespace. The benefit of this approach is that the Ingress-Nginx Controller can bind ports 80 and 443 directly to Kubernetes nodes' network interfaces, without the extra network translation imposed by NodePort Services.</p> <div class="admonition note"> <p class=admonition-title>Note</p> <p>This approach does not leverage any Service object to expose the Ingress-Nginx Controller. If the <code>ingress-nginx</code> Service exists in the target cluster, it is <strong>recommended to delete it</strong>.</p> </div> <p>This can be achieved by enabling the <code>hostNetwork</code> option in the Pods' spec.</p> <div class=highlight><pre><span></span><code><span class=nt>template</span><span class=p>:</span>
2023-10-12 19:31:18 +00:00
<span class=w> </span><span class=nt>spec</span><span class=p>:</span>
<span class=w> </span><span class=nt>hostNetwork</span><span class=p>:</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">true</span>
</code></pre></div> <div class="admonition danger"> <p class=admonition-title>Security considerations</p> <p>Enabling this option <strong>exposes every system daemon to the Ingress-Nginx Controller</strong> on any network interface, including the host's loopback. Please evaluate the impact this may have on the security of your system carefully.</p> </div> <div class="admonition example"> <p class=admonition-title>Example</p> <p>Consider this <code>ingress-nginx-controller</code> Deployment composed of 2 replicas, NGINX Pods inherit from the IP address of their host instead of an internal Pod IP.</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>-n<span class=w> </span>ingress-nginx<span class=w> </span>get<span class=w> </span>pod<span class=w> </span>-o<span class=w> </span>wide
2021-01-11 15:59:14 +00:00
<span class=go>NAME READY STATUS IP NODE</span>
<span class=go>default-http-backend-7c5bc89cc9-p86md 1/1 Running 172.17.1.1 host-2</span>
<span class=go>ingress-nginx-controller-5b4cf5fc6-7lg6c 1/1 Running 203.0.113.3 host-3</span>
<span class=go>ingress-nginx-controller-5b4cf5fc6-lzrls 1/1 Running 203.0.113.2 host-2</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> </div> <p>One major limitation of this deployment approach is that only <strong>a single Ingress-Nginx Controller Pod</strong> may be scheduled on each cluster node, because binding the same port multiple times on the same network interface is technically impossible. Pods that are unschedulable due to such situation fail with the following event:</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>-n<span class=w> </span>ingress-nginx<span class=w> </span>describe<span class=w> </span>pod<span class=w> </span>&lt;unschedulable-ingress-nginx-controller-pod&gt;
2021-01-11 15:59:14 +00:00
<span class=go>...</span>
<span class=go>Events:</span>
<span class=go> Type Reason From Message</span>
<span class=go> ---- ------ ---- -------</span>
<span class=go> Warning FailedScheduling default-scheduler 0/3 nodes are available: 3 node(s) didn&#39;t have free ports for the requested pod ports.</span>
2025-01-22 12:59:16 +00:00
</code></pre></div> <p>One way to ensure only schedulable Pods are created is to deploy the Ingress-Nginx Controller as a <em>DaemonSet</em> instead of a traditional Deployment.</p> <div class="admonition info"> <p class=admonition-title>Info</p> <p>A DaemonSet schedules exactly one type of Pod per cluster node, masters included, unless a node is configured to <a href=https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ >repel those Pods</a>. For more information, see <a href=https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/ >DaemonSet</a>.</p> </div> <p>Because most properties of DaemonSet objects are identical to Deployment objects, this documentation page leaves the configuration of the corresponding manifest at the user's discretion.</p> <p><img alt="DaemonSet with hostNetwork flow" src=../../images/baremetal/hostnetwork.jpg></p> <p>Like with NodePorts, this approach has a few quirks it is important to be aware of.</p> <h3 id=dns-resolution>DNS resolution<a class=headerlink href=#dns-resolution title="Permanent link"></a></h3> <p>Pods configured with <code>hostNetwork: true</code> do not use the internal DNS resolver (i.e. <em>kube-dns</em> or <em>CoreDNS</em>), unless their <code>dnsPolicy</code> spec field is set to <a href=https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy><code>ClusterFirstWithHostNet</code></a>. Consider using this setting if NGINX is expected to resolve internal names for any reason.</p> <h3 id=ingress-status_1>Ingress status<a class=headerlink href=#ingress-status_1 title="Permanent link"></a></h3> <p>Because there is no Service exposing the Ingress-Nginx Controller in a configuration using the host network, the default <code>--publish-service</code> flag used in standard cloud setups <strong>does not apply</strong> and the status of all Ingress objects remains blank.</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>get<span class=w> </span>ingress
2021-01-11 15:59:14 +00:00
<span class=go>NAME HOSTS ADDRESS PORTS</span>
<span class=go>test-ingress myapp.example.com 80</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> <p>Instead, and because bare-metal nodes usually don't have an ExternalIP, one has to enable the <a href=../../user-guide/cli-arguments/ ><code>--report-node-internal-ip-address</code></a> flag, which sets the status of all Ingress objects to the internal IP address of all nodes running the Ingress-Nginx Controller.</p> <div class="admonition example"> <p class=admonition-title>Example</p> <p>Given a <code>ingress-nginx-controller</code> DaemonSet composed of 2 replicas</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>-n<span class=w> </span>ingress-nginx<span class=w> </span>get<span class=w> </span>pod<span class=w> </span>-o<span class=w> </span>wide
2021-01-11 15:59:14 +00:00
<span class=go>NAME READY STATUS IP NODE</span>
<span class=go>default-http-backend-7c5bc89cc9-p86md 1/1 Running 172.17.1.1 host-2</span>
<span class=go>ingress-nginx-controller-5b4cf5fc6-7lg6c 1/1 Running 203.0.113.3 host-3</span>
<span class=go>ingress-nginx-controller-5b4cf5fc6-lzrls 1/1 Running 203.0.113.2 host-2</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> <p>the controller sets the status of all Ingress objects it manages to the following value:</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>get<span class=w> </span>ingress<span class=w> </span>-o<span class=w> </span>wide
2021-01-11 15:59:14 +00:00
<span class=go>NAME HOSTS ADDRESS PORTS</span>
<span class=go>test-ingress myapp.example.com 203.0.113.2,203.0.113.3 80</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> </div> <div class="admonition note"> <p class=admonition-title>Note</p> <p>Alternatively, it is possible to override the address written to Ingress objects using the <code>--publish-status-address</code> flag. See <a href=../../user-guide/cli-arguments/ >Command line arguments</a>.</p> </div> <h2 id=using-a-self-provisioned-edge>Using a self-provisioned edge<a class=headerlink href=#using-a-self-provisioned-edge title="Permanent link"></a></h2> <p>Similarly to cloud environments, this deployment approach requires an edge network component providing a public entrypoint to the Kubernetes cluster. This edge component can be either hardware (e.g. vendor appliance) or software (e.g. <em>HAproxy</em>) and is usually managed outside of the Kubernetes landscape by operations teams.</p> <p>Such deployment builds upon the NodePort Service described above in <a href=#over-a-nodeport-service>Over a NodePort Service</a>, with one significant difference: external clients do not access cluster nodes directly, only the edge component does. This is particularly suitable for private Kubernetes clusters where none of the nodes has a public IP address.</p> <p>On the edge side, the only prerequisite is to dedicate a public IP address that forwards all HTTP traffic to Kubernetes nodes and/or masters. Incoming traffic on TCP ports 80 and 443 is forwarded to the corresponding HTTP and HTTPS NodePort on the target nodes as shown in the diagram below:</p> <p><img alt="User edge" src=../../images/baremetal/user_edge.jpg></p> <h2 id=external-ips>External IPs<a class=headerlink href=#external-ips title="Permanent link"></a></h2> <div class="admonition danger"> <p class=admonition-title>Source IP address</p> <p>This method does not allow preserving the source IP of HTTP requests in any manner, it is therefore <strong>not recommended</strong> to use it despite its apparent simplicity.</p> </div> <p>The <code>externalIPs</code> Service option was previously mentioned in the <a href=#over-a-nodeport-service>NodePort</a> section.</p> <p>As per the <a href=https://kubernetes.io/docs/concepts/services-networking/service/#external-ips>Services</a> page of the official Kubernetes documentation, the <code>externalIPs</code> option causes <code>kube-proxy</code> to route traffic sent to arbitrary IP addresses <strong>and on the Service ports</strong> to the endpoints of that Service. These IP addresses <strong>must belong to the target node</strong>.</p> <div class="admonition example"> <p class=admonition-title>Example</p> <p>Given the following 3-node Kubernetes cluster (the external IP is added as an example, in most bare-metal environments this value is &lt;None&gt;)</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>get<span class=w> </span>node
2021-01-11 15:59:14 +00:00
<span class=go>NAME STATUS ROLES EXTERNAL-IP</span>
<span class=go>host-1 Ready master 203.0.113.1</span>
<span class=go>host-2 Ready node 203.0.113.2</span>
<span class=go>host-3 Ready node 203.0.113.3</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> <p>and the following <code>ingress-nginx</code> NodePort Service</p> <div class=highlight><pre><span></span><code><span class=gp>$ </span>kubectl<span class=w> </span>-n<span class=w> </span>ingress-nginx<span class=w> </span>get<span class=w> </span>svc
2021-01-11 15:59:14 +00:00
<span class=go>NAME TYPE CLUSTER-IP PORT(S)</span>
<span class=go>ingress-nginx NodePort 10.0.220.217 80:30100/TCP,443:30101/TCP</span>
</code></pre></div> <p>One could set the following external IPs in the Service spec, and NGINX would become available on both the NodePort and the Service port:</p> <div class=highlight><pre><span></span><code><span class=nt>spec</span><span class=p>:</span>
2023-10-12 19:31:18 +00:00
<span class=w> </span><span class=nt>externalIPs</span><span class=p>:</span>
<span class=w> </span><span class="p p-Indicator">-</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">203.0.113.2</span>
<span class=w> </span><span class="p p-Indicator">-</span><span class=w> </span><span class="l l-Scalar l-Scalar-Plain">203.0.113.3</span>
</code></pre></div> <div class=highlight><pre><span></span><code><span class=gp>$ </span>curl<span class=w> </span>-D-<span class=w> </span>http://myapp.example.com:30100
2021-01-11 15:59:14 +00:00
<span class=go>HTTP/1.1 200 OK</span>
<span class=go>Server: nginx/1.15.2</span>
2023-10-12 19:31:18 +00:00
<span class=gp>$ </span>curl<span class=w> </span>-D-<span class=w> </span>http://myapp.example.com
2021-01-11 15:59:14 +00:00
<span class=go>HTTP/1.1 200 OK</span>
<span class=go>Server: nginx/1.15.2</span>
2023-10-12 19:31:18 +00:00
</code></pre></div> <p>We assume the myapp.example.com subdomain above resolves to both 203.0.113.2 and 203.0.113.3 IP addresses.</p> </div> </article> </div> </div> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> Made with <a href=https://squidfunk.github.io/mkdocs-material/ target=_blank rel=noopener> Material for MkDocs </a> </div> </div> </div> </footer> </div> <div class=md-dialog data-md-component=dialog> <div class="md-dialog__inner md-typeset"></div> </div> <script id=__config type=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> <script src=../../assets/javascripts/bundle.aecac24b.min.js></script> </body> </html>