Skip to content

Simple example application using go + htmx + redis for demoing in K8s

Notifications You must be signed in to change notification settings

e-gineering/stayorgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Do I stay or do I Go?

Simple demo application as an example of an external state store deployed capability. Built using the Go language with GoLand and the htmx Javascript library to generate interactive DOM segments. The application requires an available Redis key value store configured through environment variables.

Demonstrated with a local K8s cluster using Orbstack and k9s for visualization

Demonstrates the following key K8s capabilities

  • Kubernetes Pod and Deployment
  • NodePort routing
  • Ingress routing
  • Configuration through environment variables
  • Deployment Health checks

Demo

Go from local development through to a deployed application

Local Development

  • Start the local container for Redis via docker-compose docker compose --file scripts/docker-compose.yaml up -d
  • Launch the Application from the IDE with configuration
  • Verify 'Hello' endpoint using localtest.http (used for health check)
  • Show the application running on http://localhost:8080

Pod Deployment

note Redis is already deployed as a running service

  • Docker build of the container docker build -t stayorgo:0.1 .
  • Show pod definition yaml
  • Deploy as a pod scripts/k8s/pod-deployment/stayorgo-pod.yaml kubectl apply -f scripts/k8s/pod-deployment/stayorgo-pod.yaml
  • Local port-forward to port 8080 kubectl port-forward stayorgo-pod 8080:8080
  • Show the application executing (connected to Redis in K8s)
  • Show shutdown without restart

Deployment Service with Nodeport

  • Show Deployment, Service and NodePort
  • Apply scripts/k8s/service-nodeport/stayorgo-service-nodeport.yaml
  • Show the application running on http://localhost:30007

Service with Ingress allowed with Nginx Ingress Controller

  • Show Deployment, Service, and Ingress
  • Apply scripts/k8s/service-ingress/stayorgo-service-ingress.yaml
  • Show the application running on http://stayorgo.k8s.orb.local
  • Show scaling the application
  • Show deleting a replica
  • Show restarting a deployment

Nginx Ingress Installation (preliminary to the demo)

Helm Install

Tested with version 3.4

Install the Ingress controller and CRDs directly using the default values and the yaml. Instructions

Get the CRDs to install ahead of the Helm chart installation Install CRD

cd kubernetes-ingress/deployments/common
kubectl apply -f ingress-class.yaml

cd kubernetes-ingress/deploy
kubectl apply -f crds.yaml
# results in 
customresourcedefinition.apiextensions.k8s.io/dnsendpoints.externaldns.nginx.org created
customresourcedefinition.apiextensions.k8s.io/globalconfigurations.k8s.nginx.org created
customresourcedefinition.apiextensions.k8s.io/policies.k8s.nginx.org created
customresourcedefinition.apiextensions.k8s.io/transportservers.k8s.nginx.org created
customresourcedefinition.apiextensions.k8s.io/virtualserverroutes.k8s.nginx.org created
customresourcedefinition.apiextensions.k8s.io/virtualservers.k8s.nginx.org created

Helm install first uses the OCI pulled chart

The version is the Chart version and not the application version

helm pull oci://ghcr.io/nginxinc/charts/nginx-ingress --untar --version 1.1.2

goto the pulled directory

cd nginx-ingress

apply the controller using the default values

helm install nginx-ingress-3-4 .

I chose the name nginx-ingress-3-4 for the helm install also . chooses the default values.yaml (look it over first for your desired configuration)

The default configuration listens on port 80 and 443 for routing

Reference Links

Why readiness and healthiness tests are important Hello IT, have you tried turning it off and on again?

Spending more on Kubernetes due to overprovisioning compute resources InfoQ Article