I have a small addiction with Kubernetes. I run K8S on my homelab of 3 Dell Optiplexes, as well as doing K8S all day at my job. It's a lot of fun. So when I needed to host this website, I decided to do it on my cluster rather than on some cloud provider. Just for starters, I have Cloudflare with DDNS setup to my home IP address.
My first step is containerising the website to run with Docker. I'll use Nginx for my webserver, and the config is pretty simple. Here!
Now that works, all I need to do is create the Dockerfile.
This isn't exactly best practices as I have to rebuild the docker image everytime I make a change, and redeploy it. But, it's not like this site is huge either, I could probably run it from a MilkV Duo :P.
At some point in the future, I'll create a Github action to auto-build the Docker image and push to Dockerhub. However, for now, it's manual (which is fine for me anyway).
The last step is deploying the image to Kubernetes. I do this through a handful of manifests which dictate the state of the deployment.
apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: nyanyamachine name: nyanyamachine spec: replicas: 1 selector: matchLabels: app: nyanyamachine strategy: {} template: metadata: creationTimestamp: null labels: app: nyanyamachine spec: containers: - image: nyanyamachine:latest name: nyanyamachine resources: {} status: {}
And finally create the service to expose the deployment.
apiVersion: v1 kind: Service metadata: name: nyanyamachine-service labels: app: nyanyamachine spec: selector: app: nyanyamachine ports: - protocol: TCP port: 80 targetPort: 80 type: LoadBalancer
At this point, I can create an Ingress, but instead I'll go ahead and make an entry in Caddy, my reverse proxy. This is more convenient for me than Ingress with Certmanager as I have had issues in the past.