Skip to content

dshatokhin/bagapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bagapi

Container image

Stored in Gitlab Registry with a public access (latest tag only):

ghcr.io/dshatokhin/bagapi:latest

Quick start

Requirements:

Deploy

First, deploy the Kubernetes cluster (UpCloud in our case - authentication needed via env vars - UPCLOUD_USERNAME and UPCLOUD_PASSWORD):

> pkl eval tofu/main.pkl -m tofu/
> tofu -chdir=tofu init
> tofu -chdir=tofu apply -auto-approve
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Save kubeconfig:

> tofu -chdir=tofu output -raw kubeconfig > ./bagapi-cluster.yaml
> export KUBECONFIG=$PWD/bagapi-cluster.yaml

Apply Gateway API CRDs to created cluster:

> kubectl apply -f crd/
customresourcedefinition.apiextensions.k8s.io/gateways.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/gatewayclasses.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/httproutes.gateway.networking.k8s.io created

Install bagapi-provisioner by running:

> pkl eval bagapi/deploy.pkl -p createNamespace=true | kubectl apply -f -
namespace/bagapi-system created
deployment.apps/bagapi-provisioner created
serviceaccount/bagapi-provisioner created
clusterrole.rbac.authorization.k8s.io/bagapi created
clusterrolebinding.rbac.authorization.k8s.io/bagapi-provisioner created

Deploy kuard to cluster, lets start with one instance - blue:

> pkl eval kuard/deploy.pkl -p createNamespace=true -p colours=blue | kubectl apply -f -
namespace/kuard created
gatewayclass.gateway.networking.k8s.io/bagapi created
gateway.gateway.networking.k8s.io/kuard created
deployment.apps/kuard-blue created
service/kuard-blue created
httproute.gateway.networking.k8s.io/kuard-blue created

After a few minutes the LoadBalancer will be created in the cloud, use the IP address to populate /etc/hosts. We've got an FQDN so additional steps needed to resolve the hostname to the IP:

# Get and resolve LB hostname to IP address
> LB_HOSTNAME=$(kubectl get svc kuard-bagapi -n kuard -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
> LB_ADDRESS=$(dig +short "$LB_HOSTNAME")

# Save to /etc/hosts
> cat << EOF | sudo tee -a /etc/hosts

$LB_ADDRESS    blue.online
$LB_ADDRESS    green.online
$LB_ADDRESS    purple.online
EOF

The blue.online instance should be ready to open in browser or simply curled:

> curl --write-out '\n' --dump-header - http://blue.online/healthy
HTTP/1.1 200 OK
content-type: text/plain
date: Thu, 06 Jun 2024 20:01:35 GMT
content-length: 2
x-envoy-upstream-service-time: 0
server: envoy

ok

Add other variants of kuard:

> pkl eval kuard/deploy.pkl -p createNamespace=true -p colours=blue,green,purple | kubectl apply -f -
namespace/kuard unchanged
gatewayclass.gateway.networking.k8s.io/bagapi unchanged
gateway.gateway.networking.k8s.io/kuard unchanged
deployment.apps/kuard-blue unchanged
service/kuard-blue unchanged
httproute.gateway.networking.k8s.io/kuard-blue unchanged
deployment.apps/kuard-green created
service/kuard-green created
httproute.gateway.networking.k8s.io/kuard-green created
deployment.apps/kuard-purple created
service/kuard-purple created
httproute.gateway.networking.k8s.io/kuard-purple created

Now all 3 instances can be accessed by dicrect links:

Let's enable HTTPS:

> pkl eval kuard/deploy.pkl -p createNamespace=true -p colours=blue,green,purple -p enableHttps=true | kubectl apply -f -
namespace/kuard unchanged
gatewayclass.gateway.networking.k8s.io/bagapi unchanged
gateway.gateway.networking.k8s.io/kuard configured
deployment.apps/kuard-blue unchanged
service/kuard-blue unchanged
httproute.gateway.networking.k8s.io/kuard-blue unchanged
deployment.apps/kuard-green unchanged
service/kuard-green unchanged
httproute.gateway.networking.k8s.io/kuard-green unchanged
deployment.apps/kuard-purple unchanged
service/kuard-purple unchanged
httproute.gateway.networking.k8s.io/kuard-purple unchanged
> curl --insecure --write-out '\n' --dump-header - https://blue.online/healthy
HTTP/1.1 200 OK
content-type: text/plain
date: Thu, 06 Jun 2024 20:11:23 GMT
content-length: 2
x-envoy-upstream-service-time: 0
server: envoy

ok

Destroy

To avoid creating any orphaned resources in the cloud first delete workload from cluster:

> pkl eval kuard/deploy.pkl -p createNamespace=true | kubectl delete -f -

After that the cluster could be destroyed with tofu:

> tofu -chdir=tofu destroy -auto-approve

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published