Skip to content
/ krud Public

Trying out cloud stuff with a crude CRUD app.

Notifications You must be signed in to change notification settings

vikblom/krud

Repository files navigation

KRUD

Stack

Database

Postgresql running in a Docker container.

github.com/jackc/pgx/v4 with the stblib package so the interface is plain ol' database/sql.

HTTP

Gorilla mux but otherwise http and httptest.

Probably missing some tricks and best practices to make to code smaller/simpler.

Testing

Standard library.

Database tests require an env var set to some psql DB. Just putting sqlite in a t.TmpDir() would be much simpler.

httptest for endpoint tests. Low coverage due to lack of time. Is there a good way of comparing expected vs. actual response vs. actual db change?

TODO

  • Use anon. struct with json tags for API?
  • Validate incoming Content Type.
  • HTTPS.
  • Log stmts across handlers and db.
  • k8s secrets.
  • k8s persistence.
  • Better "Update" API.

Minikube

Develop w/o a docker registry

Use images built locally under minikube for simplicity (skips any registry). Pre-load the DB image with an init-file containing the schema.

minikube start
alias 'kubectl' 'minikube kubectl --'

kubectl get all
kubectl logs -fl app=krud-http-deployment

kubectl port-forward service/krud-psql-service 2345:2345
kubectl port-forward service/krud-http-service 8080:8080
minikube service --url service-name krud-http-service

kubectl delete deployment --all

Using minikube and GCP docker registry

Pulling down images proved to be quite tricky. If docker login works that can be made into a k8s secret:

kubectl create secret generic regcred \
    --from-file=.dockerconfigjson=$HOME/.docker/config.json \
    --type=kubernetes.io/dockerconfigjson
kubectl patch serviceaccount default \
    -p '{"imagePullSecrets": [{"name": "regcred"}]}'
kubectl get serviceaccount default -o yaml

GCP

More or less: https://cloud.google.com/kubernetes-engine/docs/deploy-app-cluster . After provisioning resources deplyoment is just:

make images
gcloud container clusters get-credentials kube-cluster
kubectl apply -f deploy

Useful Links

About

Trying out cloud stuff with a crude CRUD app.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages