This should be a very quick & dirty way to reverse proxy a web server or service not hosted in Kubernetes using an Nginx container and an Ingress controller.
These are light weight and low resource enough that if you need multiple, you
ought to run one overlay
per host you are reverse-proxying. They're also
delightfully self-cleaning since they create and destroy the entire namespace.
- A functional k8s cluster.
- An Ingress provider (I use
ingress-nginx
, not to be confused withnginx-ingress
)
- A TLS secret suitable for an Ingress route. If you plan on securing your Pi-hole
server with TLS encryption, you need to either create a TLS secret before hand,
or modify
patches/ingress/settings.yaml
to do the Let's Encrypt part for you automatically.
The options I needed are in the patches
subdirectory. Feel free to edit and
add as much as needed for your needs.
I will go through the options I've sanitized in order:
Paste in your Nginx reverse proxy configuration. The included example should be sufficient to get you started. There are many more options than can be discussed here. It should suffice here that the proxy is just doing simple pass-through to the endpoint behind.
Edit this to suit. The defaults are kind of aggressive for a small proxy, so I made them less aggressive with only 4 workers and 128 connections per worker. If you know what you're doing, then you can edit these accordingly. If you are only proxying a lightweight, low-traffic webserver, then these should be fine.
Make any changes here, as needed--particularly to the CPU and memory resources
.
The defaults here should suffice for a lightweight, low-traffic webserver, but
you can dial those settings up however you need.
If you plan on using TLS to terminate, set <MY_TLS_SECRET>
and
<REVERSE.EXAMPLE.COM>
. You will also need to uncomment the patch section in
kustomization.yaml
.
Replace <REVERSE-PROXY>
with your chosen namespace. This must be done both for
namespace:
at the top of the file and in the patches:
section for replacing
namespace:
## Namespace settings
## Change <REVERSE-PROXY> to match whatever you put in namespace above
- patch: |-
- op: replace
path: /metadata/name
value: <REVERSE-PROXY>
<REVERSE.EXAMPLE.COM>
should be the FQDN that hosts the UI, and match what was
used in patches/statefulset/settings.yaml
If you plan to use TLS to secure your ingress, be sure to uncomment these lines:
# - patch:
# path: patches/ingress/settings.yaml
and edit patches/ingress/settings.yaml
to set <MY_TLS_SECRET>
and
<REVERSE.EXAMPLE.COM>
.
(Optional) To preview generated configuration before deploying:
kubectl kustomize .
Run the following command to build and deploy:
kubectl apply -k .
-
Copy
kustomization.yaml
, and the variouspatches/*
files tooverlays/NAME
, or whatever directory structure you prefer. -
Each
overlays/NAME
should have its ownkustomization.yaml
andpatches
subdirectory. -
Be sure to update the
resources
section ofkustomization.yaml
to be able to reach thebase
directory:resources: - ../../base
Apply the same configuration steps as above for each overlay/NAME
path you
create.
(Optional) To preview generated configuration before deploying:
kubectl kustomize overlays/NAME
Run the following command to build and deploy:
kubectl apply -k overlays/NAME