<p>Is it possible to simplify this chain that runs on bare metal:</p>

<ol>
<li>StatefulSet with replicas count that will change over the time</li>
<li>Service</li>
<li>Nginx-ingress with <code>proxy-next-upstream: "error http_502 timeout invalid_header non_idempotent"</code></li>
<li>Pod with Nginx for caching and many other things that ingress can't do</li>
<li>Service type: LoadBalancer</li>
<li><a href="https://github.com/danderson/metallb" rel="nofollow noreferrer">MetalLB</a></li>
</ol>

<p>Is it possible to simplify this stack?</p>

Jonas
<p>Yes if you turn nginx into sidecar (deploy in every pod) + remove ingress. Cache is not shared in this case: </p>

<ol>
<li>StatefulSet with replicas count that will change over the time</li>
<li>Sidecar (means in every replica) with nginx for caching and many other things that ingress can't do, including the ingress settings you used. Proxy pass to <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/#resource-sharing-and-communication" rel="nofollow noreferrer">localhost</a> in this case.</li>
<li>Service: LoadBalancer</li>
<li>MetalLB</li>
</ol>

<p>Or if you need a common cache - just throw away the ingress:</p>

<ol>
<li>StatefulSet</li>
<li>ServiceA (pointing to StatefulSet): <a href="https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" rel="nofollow noreferrer">ClusterIP</a></li>
<li>nginx with caching and hacks. Proxy pass to ServiceA.namespace.svc.cluster.local</li>
<li>ServiceB (pointing to nginx deployment): LoadBalancer</li>
<li>MetalLB</li>
</ol>
