Example of a distributed voting app running on Kubernetes. Written in Golang with Terraform definitions to deploy to AWS EKS

Overview

Kubernetes distributed voting app

License: MIT

☸️ Example of a distributed voting app running on Kubernetes. Written in Golang with Terraform definitions to deploy to AWS


Table of Contents

Presentation

This repository provide a complete and modern ready to deploy example of a dockerized and distributed app. Deployable using Docker-Compose, Kubernetes templates or even Helm Chart.

Architecture

App's architecture scheme

Project structure

k8s-voting-app-aws/
├─ .github/ # Github workflows
├─ docs/
│  ├─ app-architecture.jpg # App's architcture scheme
│  ├─ README-FR.md # French translation of the readme
├─ helm/ # Helm Chart definitions
├─ k8s-specifications/ # K8s Templates files
├─ voting-app/ # Result, Vote and Worker source code 
├─ *.tf # terraform specs files
├─ *.tfvars # terraform values files
├─ *.yml # docker-compose files

Getting Started

Run with Docker Compose

  1. Download and install Docker and Docker-Compose
  2. Clone this repository: git clone [email protected]:hbollon/k8s-voting-app-aws.git (you can alternatively use http)
  3. Open a terminal inside the cloned repository folder and build Docker images: docker-compose build
  4. Start all services: docker-compose up -d

The result app should be now accessible through localhost:9091 and the vote one to localhost:9090 To stop all deployed ressources run: docker-compose down

Run with Kubernetes

Minikube

Before deploying the app, you must install Minikube and start a cluster:

  1. Install Minikube
  2. Start a Minikube cluster: minikube start
  3. Check that Minikube is fully up (minikube status) and kubectl successfully linked (kubectl get pods -A)
  4. Enable Nginx Ingress Controller addon: minikube addons enable ingress
Using k8s templates
  1. Deploy all k8s ressources: kubectl apply -f k8s-specifications --namespace=voting-app-stack
  2. Get your cluster IP using: minikube ip
  3. Enable ingress access:
    • On Linux: Edit your hosts file located at /etc/hosts by adding result.votingapp.com vote.votingapp.com to the end of it, of course replace by the real cluster ip.
    • On Windows: Edit your hosts file located at c:\Windows\System32\Drivers\etc\hosts by adding 127.0.0.1 result.votingapp.com vote.votingapp.com to the end of it. After that, start a Minikube tunnel: minikube tunnel

The result app should be now accessible through result.votingapp.com and the vote one to vote.votingapp.com To stop and destroy all k8s deployed ressources run: kubectl delete -f k8s-specifications --namespace=voting-app-stack and stop minikube using minikube stop

Using Helm Chart
  1. Update Helm repositories and download dependencies: helm dependency update ./helm/voting-app
  2. Deploy the Helm Chart: helm template voting-app ./helm/voting-app --namespace=voting-app-stack | kubectl apply -f -
  3. Get your cluster IP using: minikube ip
  4. Enable ingress access:
    • On Linux: Edit your hosts file located at /etc/hosts by adding result.votingapp.com vote.votingapp.com to the end of it, of course replace by the real cluster ip.
    • On Windows: Edit your hosts file located at c:\Windows\System32\Drivers\etc\hosts by adding 127.0.0.1 result.votingapp.com vote.votingapp.com to the end of it. After that, start a Minikube tunnel: minikube tunnel

The result app should be now accessible through result.votingapp.com and the vote one to vote.votingapp.com To stop and destroy all k8s deployed ressources run: helm template voting-app ./helm/voting-app --namespace=voting-app-stack | kubectl delete -f - and stop minikube using minikube stop

AWS

To deploy the app to AWS you must create an infrastructure based on EKS (Elastic Kubernetes Service) first. You have all the needed Terraform definitions to do that easily with an IAC interface (Infrastructure As Code). You must have an AWS account to follow this guide and be careful, although AWS has free tier for new accounts, this infrastructure can generate some costs although very limited. Especially in case of bad configuration or usage where the costs can be multiplied.

I will not be responsible for the invoice generated in any way.

  1. Install Terraform, AWS-CLI and KubeCTL

  2. Clone this repo

  3. Create a new IAM User on your AWS Account:

    • Go to the IAM section and create a new user named "TerraformUser"
    • Add this user to a new group named "TerraformFullAccessGroup" with AdministratorAccess and AmazonEKSClusterPolicy rights
    • Once done, keep the Secret Access Key and Access Key ID, this will be the only time AWS gives it to you
  4. Go to the VPC panel of the AWS Console and get two differents subnet ids from the default VPC. Add these two ids in the values.tfvars file at the root of this project (replace and ).

  5. For the following steps you will need to use a credentials management method to use them with Terraform and AWS-CLI. The easier way is to set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environement variables. But you can also use tools like Summon or AWS config files.

  6. Open a console at the root of this project directory and execute:

  • terraform init
  • terraform plan -var-file=values.tfvars: check that the output is generated without any errors.
  • terraform apply -var-file=values.tfvars (this operation can take a while don't worry)
  1. If previous commands runs well you should now have a working EKS cluster, in order to link your kubectl installation to it you must run: aws eks update-kubeconfig --region eu-west-3 --name eks_cluster_voting_app change the region flag if you have deployed the EKS on another one. Once done, run kubectl get pods -A, if it working you've done with your fresh EKS cluster.

  2. Finally, deploy all the k8s ressources:

    • With k8s templates: kubectl apply -f k8s-specifications --namespace=voting-app-stack
    • With Helm Chart: helm dependency update ./helm/voting-app and after: helm template voting-app ./helm/voting-app --namespace=voting-app-stack | kubectl apply -f -

You have the possibility to get the aws endpoint linked to your EKS cluster by running: terraform output -json. However, the ingress ressource is not compatible with it atm.

You can destroy everything just by running this command: terraform destroy -var-file=values.tfvars

Never delete the generated .tfstate file when the infrastucture is deployed! Without it you will be unable to delete all the AWS ressources with Terraform and you will be forced to do it manually with the Web AWS Console or the AWS-CLI.

Roadmap

Many additional features are coming, including:

  • Ingress compatibility with AWS and domain customization
  • Monitoring/Alerting/Dashboarding using kube-prometheus-stack
  • Style webapps with CSS
  • And many more to come !

🤝 Contributing

Contributions are greatly appreciated!

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some amazing stuff')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Create a new Pull Request

Issues and feature requests are welcome! Feel free to check issues page.

Author

👤 Hugo Bollon

Show your support

Give a ⭐️ if this project helped you! You can also consider so sponsor me here ❤️

📝 License

This project is under MIT license.

Owner
Hugo Bollon
Student at University Savoie Mont-Blanc in CS Master and DevOps Engineer at Camptocamp SA. I don't know everything but I can learn anything
Hugo Bollon
Simple-go-api - This porject deploys a simple go app inside a EKS Cluster

SimpleGoApp This porject deploys a simple go app inside a EKS Cluster Prerequisi

null 0 Jan 17, 2022
A simple Go app and GitHub workflow that shows how to use GitHub Actions to test, build and deploy a Go app to Docker Hub

go-pipeline-demo A repository containing a simple Go app and GitHub workflow that shows how to use GitHub Actions to test, build and deploy a Go app t

Marat Bogatyrev 0 Nov 17, 2021
Deploy 2 golang aws lambda functions using serverless framework.

Deploy 2 golang aws lambda functions using serverless framework.

NguyenTheAnh 0 Jan 20, 2022
A golang tool to list out all EKS clusters with active nodegroups in all regions in json format

eks-tool A quick and dirty tool to list out all EKS clusters with active nodegro

null 0 Dec 18, 2021
This repository contains Prowjob configurations for Amazon EKS Anywhere.

Amazon EKS Anywhere Prow Jobs This repository contains Prowjob configuration for the Amazon EKS Anywhere project, which includes the eks-anywhere and

Amazon Web Services 12 Jan 4, 2022
Run Amazon EKS on your own infrastructure 🚀

Amazon EKS Anywhere Conformance test status: Amazon EKS Anywhere is a new deployment option for Amazon EKS that enables you to easily create and opera

Amazon Web Services 1.4k Jan 14, 2022
Triggers an update to a Koyeb app service to re-deploy the latest docker image

Triggers an update to a Koyeb app service to re-deploy the latest docker image

Reece May 3 May 5, 2021
KEDA is a Kubernetes-based Event Driven Autoscaling component. It provides event driven scale for any container running in Kubernetes

Kubernetes-based Event Driven Autoscaling KEDA allows for fine-grained autoscaling (including to/from zero) for event driven Kubernetes workloads. KED

KEDA 4.1k Jan 18, 2022
Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes.

Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes. This project is inspired by agones. Introduction Genera

Open Cloud-native Game-application Initiative 24 Dec 29, 2021
The OCI Service Operator for Kubernetes (OSOK) makes it easy to connect and manage OCI services from a cloud native application running in a Kubernetes environment.

OCI Service Operator for Kubernetes Introduction The OCI Service Operator for Kubernetes (OSOK) makes it easy to create, manage, and connect to Oracle

Oracle 11 Nov 10, 2021
kitex running in kubernetes cluster and discover each other in kubernetes Service way

Using kitex in kubernetes Kitex [kaɪt'eks] is a high-performance and strong-extensibility Golang RPC framework. This go module helps you to build mult

adolli 1 Nov 30, 2021
Terraform-provider-buddy - Terraform Buddy provider For golang

Terraform Provider for Buddy Documentation Requirements Terraform >= 1.0.11 Go >

Buddy 1 Jan 5, 2022
Build and deploy Go applications on Kubernetes

ko: Easy Go Containers ko is a simple, fast container image builder for Go applications. It's ideal for use cases where your image contains a single G

Google 3.9k Jan 21, 2022
Flux is a tool for keeping Kubernetes clusters in sync with sources of configuration, and automating updates to configuration when there is new code to deploy.

Flux is a tool for keeping Kubernetes clusters in sync with sources of configuration (like Git repositories), and automating updates to configuration when there is new code to deploy.

Flux project 2.6k Jan 15, 2022
httpserver deploy in kubernetes

httpserver deploy in kubernetes cluster What is this? The project realizes the functions of mainstream httpserver based on golang / gin, including ele

jiaxi chen 0 Jan 1, 2022
Christmas Hack Day Project: Build an Kubernetes Operator to deploy Camunda Cloud services

Camunda Cloud Operator Christmas Hack Day Project (2021): Build an Kubernetes Operator to deploy Camunda Cloud services Motiviation / Idea We currentl

Camunda Community Hub 0 Dec 19, 2021
Digitalocean-kubernetes-challenge - Deploy a GitOps CI/CD implementation

DigitalOcean Kubernetes Challenge 2021 I chose to participate in the DigitalOcean Kubernetes Challenge in order to learn more about Kubernetes and to

Engin Diri 2 Jan 12, 2022
A plugin for running Open Policy Agent (OPA) in AWS Lambda as a Lambda Extension.

opa-lambda-extension-plugin A custom plugin for running Open Policy Agent (OPA) in AWS Lambda as a Lambda Extension. To learn more about how Lambda Ex

GoDaddy 18 Jan 11, 2022
Create AWS Auto Scaling groups from running instances or AMIs automatically.

AWS Auto Scaling Groups Builder AWS Auto Scaling group is a great way of managing Amazon EC2 instances. AWS Auto Scaling group watches the correspondi

Alexey Shagraev 1 Jan 7, 2022