KubeVoyage Part 1: A Kubernetes Auth Proxy with Svelte and Go
In this post, I detail the development process and architectural choices for KubeVoyage
, a Kubernetes authentication proxy that integrates both human and AI-generated code. The project aims to facilitate user access management across various sites by leveraging Kubernetes for deployment and orchestration.
Project Overview
KubeVoyage
serves as an authentication proxy, utilizing annotations in ingress to direct requests to its container. This container consists of three primary components: a frontend built with Svelte, a backend developed in Go, and an SQL database for data management. The system supports two types of user roles: 'admin' and 'user', with admins having the ability to grant access to sites.
Frontend Implementation
The frontend of KubeVoyage
is developed using Svelte, a component-based JavaScript framework chosen for its efficiency and simplicity. The interface includes a login page and an administrative panel where admins can review and manage user access requests. For styling, the Bootstrap framework was integrated, and Single Sign-On (SSO) capabilities were added with support for Google, GitHub, and Microsoft authentication methods.
Backend Architecture
The backend is implemented in Go due to its performance advantages and simplicity. To manage interactions with the SQL database, the GORM library, an object-relational mapper (ORM) for Go, was employed. This choice allows for compatibility with various SQL databases, including PostgreSQL and SQLite. The backend's responsibilities include serving the frontend, authenticating users, and processing access requests. It also provides API endpoints for the frontend to retrieve necessary data.
Deployment Using Kubernetes and Helm
For deployment, a Helm chart was developed for KubeVoyage
, facilitating its deployment on Kubernetes environments. Helm assists in defining and managing the necessary Kubernetes resources such as services and deployments, ensuring a scalable and maintainable application deployment.
Challenges Encountered
Several technical challenges were addressed during development:
-
CORS Configuration: The integration of the frontend and backend required CORS (Cross-Origin Resource Sharing) configuration to allow for proper interaction between different components.
-
Svelte Routing: Implementing client-side routing in Svelte necessitated adjustments to ensure that refreshing the browser on specific routes would not result in a 404 error. This was resolved by configuring the backend to serve the main
index.html
file for any routing requests. -
Bootstrap Icon Integration: The inclusion of Bootstrap icons within the Svelte framework required path adjustments and proper loading of font files to ensure correct icon display.
Contribution of ChatGPT
A significant portion of the initial codebase, particularly in defining core logic and structure, was generated by ChatGPT with specific guidance and instructions provided. This collaboration highlighted the potential of integrating AI in software development processes, offering efficiency gains in prototyping and coding.
Conclusion
The development of KubeVoyage
illustrates the application of contemporary software development tools and practices, including the integration of AI-generated code. The project demonstrates a practical approach to developing a Kubernetes-based authentication proxy, with considerations for scalability, user experience, and maintainability. This report aims to provide a clear understanding of the project's development journey and architectural decisions.
In the vast ocean of software development, creating a Kubernetes authentication proxy might seem like a daunting task. But what if I told you that a significant portion of such an application was written by a machine, specifically ChatGPT, with just a bit of human guidance? Intrigued? Let's dive into the journey of building KubeVoyage
.
Introduction
KubeVoyage
is a Kubernetes authentication proxy designed to streamline user access to various sites. The core concept is simple: annotate an ingress, and the request is forwarded to the KubeVoyage
container. This container houses a frontend built with Svelte, a backend written in Go, and an SQL database. Users can either have an 'admin' or 'user' role, with admins having the power to grant site access.
The Frontend: Svelte Magic
Svelte, a component-based JavaScript framework, was chosen for its simplicity and power. The frontend consists of a login page and a list of user access requests. Admins can view these requests and either accept or deny them.
To enhance the user experience, we integrated Bootstrap for styling and added Single Sign-On (SSO) icons for platforms like Google, GitHub, and Microsoft.
The Backend: Go with GORM
Go, with its performance and simplicity, was the natural choice for the backend. We used the GORM library, an ORM for Go, to interact with our SQL database. This allowed us to support multiple SQL databases like PostgreSQL and SQLite.
The backend serves the frontend, handles authentication, and manages user access requests. It also provides endpoints for the frontend to fetch data, like the list of user access requests.
Kubernetes and Helm
To deploy KubeVoyage
on Kubernetes, we crafted a Helm chart. Helm, the package manager for Kubernetes, allows for easy deployment, scaling, and management of applications. The Helm chart defines the necessary services, deployments, and configurations required to run KubeVoyage
seamlessly.
Challenges and Solutions
During development, we faced a few challenges:
-
CORS Issues: When running both the frontend and backend servers during development, CORS (Cross-Origin Resource Sharing) issues arose. We tackled this by configuring the Go backend to handle CORS, allowing requests from our frontend.
-
Routing with Svelte: Client-side routing posed a challenge when refreshing the browser on specific routes, leading to a 404 error. The solution? Configuring the backend to always serve the main
index.html
and letting the client-side router handle the rest. -
Icon Loading with Bootstrap: We encountered issues loading Bootstrap icons in Svelte due to path discrepancies. The solution involved adjusting the paths and ensuring the font files were correctly loaded.
The Role of ChatGPT
The fascinating part of this journey was the role of ChatGPT. Through continuous prompts and guidance, ChatGPT produced the core logic, structure, and code for KubeVoyage
. It was like having a pair-programming partner that could generate vast amounts of code on-demand, allowing for rapid prototyping and development.
Conclusion
KubeVoyage
stands as a testament to the power of modern development tools and methodologies. With the right guidance, even machine-generated code can lead to functional and powerful applications. Whether you're a seasoned developer or just starting, leveraging tools like ChatGPT can supercharge your development process.
I hope this article provides a comprehensive overview of the KubeVoyage
project and the unique development process behind it. It's truly a blend of human creativity and machine efficiency!