From Zero to Hero: Our Kubernetes Journey with Mercury Bot
Setting up a production-ready Kubernetes cluster can be a challenging journey, filled with unexpected twists and turns. Today, we want to share our experience of deploying the Mercury Bot on Kubernetes, complete with proper networking, HTTPS, and all the fun debugging that came with it.
The Initial Setup
Our journey began with a basic Kubernetes installation on a Hetzner server. The goal was simple: deploy our Mercury Bot service and make it accessible to the world. But as with many things in tech, what seems simple at first can quickly become an adventure.
Challenge #1: Pod Networking
The first major hurdle we encountered was pod networking. Our pods were stuck in a ContainerCreating state with the cryptic error:
Failed to create pod sandbox: failed to setup network for sandbox: plugin type="flannel" failed (add): loadFlannelSubnetEnv failed
The issue? Flannel wasn't properly configured. The solution involved:
- Loading the necessary kernel modules (
br_netfilterandoverlay) - Configuring system parameters for networking
- Ensuring the Flannel CNI plugin was properly installed
Challenge #2: Ingress Controller Setup
With pod networking solved, we moved on to setting up the ingress controller. We chose nginx-ingress-controller for its robustness and flexibility. However, we faced several issues:
- Port conflicts with a system-level Nginx installation
- Admission webhook configuration issues
- Default backend routing problems
The solution was a methodical approach:
- Disabling the system Nginx service
- Cleaning up the admission webhooks
- Configuring the ingress controller with proper host networking
Challenge #3: SSL/TLS Configuration
The final piece of the puzzle was setting up HTTPS. Initially, we had a self-signed certificate, which worked but wasn't ideal for production. We had Let's Encrypt certificates on the host but weren't using them in Kubernetes.
The solution was elegant:
- Creating a Kubernetes TLS secret from existing Let's Encrypt certificates
- Configuring the ingress resource to use this secret
- Restarting the ingress controller to pick up the new certificate
The Final Architecture
Our final setup includes:
- Kubernetes cluster with Flannel networking
- nginx-ingress-controller for traffic routing
- Let's Encrypt certificates for HTTPS
- Mercury Bot service running with proper networking and security
Key Learnings
- Layer by Layer: Solve problems one layer at a time - networking, then ingress, then SSL
- Debug Methodically: Use
kubectl describe, logs, and system tools to understand issues - Security First: Proper SSL certificates are crucial for production deployments
- Documentation: Keep track of configurations and solutions for future reference
Conclusion
While the journey had its challenges, we now have a robust, secure, and properly configured Kubernetes setup. The Mercury Bot is accessible via HTTPS at mercury.arcana.cfd, and we have a solid foundation for future services.
Remember: Kubernetes complexity comes with great power, but with methodical debugging and persistence, any issue can be solved.
Next Steps
- Set up monitoring and logging
- Implement automatic certificate renewal
- Add horizontal pod autoscaling
- Document deployment procedures
Stay tuned for more updates on our Kubernetes journey!
