Skip to content
William Kennedy edited this page Jul 14, 2020 · 27 revisions

Requirements

This project has been configured to run in a Kubernetes (k8s) environment. A decision was made to use KIND for the local k8s environment. Any k8s environment would work after careful setup of your k8s cluster. This section is not going to talk about installing your own k8s environment. Instead, it will focus on using KIND for your k8s environment, setting up your cluster there and deploying and running the project locally. The project also uses Kustomize to help manage k8s configuration files.

To install KIND follow these instructions.

To install the K8s kubectl client follow these instructions.

To install the Kustomize client follow these instructions.

Commands

Run these commands in the order they are presented.

make all

This command builds all the containers for use in the K8s cluster.

$ make all

make kind-up

This command will start the cluster via Docker. It assigns the name ardan-starter-cluster to the cluster and configures the cluster to run as a single Node for simplicity. It also opens all ports for easy development access.

$ make kind-up

kind create cluster --name ardan-starter-cluster --config z/k8s/dev/kind-config.yaml

make kind-down

This command will delete the KIND cluster and everything inside of it.

$ make kind-down

kind delete cluster --name ardan-starter-cluster

make kind-load

This command loads the sales-api and metrics containers into the k8s environment. The zipkin and postgres containers don't need to be loaded since K8s can find them in the Docker registry.

$ make kind-load

kind load docker-image gcr.io/ardan-starter-kit/sales-api-amd64:1.0 --name ardan-starter-cluster
kind load docker-image gcr.io/ardan-starter-kit/metrics-amd64:1.0 --name ardan-starter-cluster

make kind-services

This command deploys two PODS into the cluster. One POD is for the Postgres database and the second POD contains the sales-api, metrics and zipkin services.

$ make kind-services

kustomize build z/k8s/dev | kubectl apply -f -

make kind-logs

This command shows the logs from the services running inside the sales-api POD. This will show the current logs and maintain the watch.

$ make kind-logs

kubectl logs -lapp=sales-api --all-containers=true -f

make kind-status

The command provides status information about the cluster. It is useful when loading new instances of the serivces.

$ make kind-status

kubectl get nodes
kubectl get pods --watch

make kind-status-full

The command provides detailed information about the services running inside the sales-api pod. Useful for debugging loading issues.

$ make kind-status-full

kubectl describe pod -lapp=sales-api

make kind-sales

This command provides a mechanism for building, loading and updating code changes from the sales-api service inside the running k8s environment.

$ make kind-sales

-- Builds new docker image for the `sales-api`
kind load docker-image sales-api-amd64:1.0 --name ardan-starter-cluster
kubectl delete pods -lapp=sales-api

make kind-metrics

This command provides a mechanism for building, loading and updating code changes from the metrics service inside the running k8s environment.

$ make kind-metrics

-- Builds new docker image for the `metrics`
kind load docker-image metrics-amd64:1.0 --name ardan-starter-cluster
kubectl delete pods -lapp=sales-api

Seed Database

You are now ready to test if the system is operational. You must seed the database just like when working in your development environment. Since the databsae port is not exposed, the admin tool has been added to the sales-api container to run the seed command.

Get information about the pod. You need the pod name.

$ make kind-shell

kubectl exec -it $(POD_NAME) --container app -- /bin/sh

Now run the migrate command to structure the database and seed to populate it with data.

$ ./admin --db-disable-tls=1 migrate
$ ./admin --db-disable-tls=1 seed

Authenticated Requests

Before any requests can be sent you must acquire an auth token. Make a request using HTTP Basic auth with the test user email and password to get the token.

$ curl --user "[email protected]:gophers" http://0.0.0.0:3000/v1/users/token

I suggest putting the resulting token in an environment variable like $TOKEN.

$ export TOKEN="COPY TOKEN STRING FROM LAST CALL"

To make authenticated requests put the token in the Authorization header with the Bearer prefix.

$ curl -H "Authorization: Bearer ${TOKEN}" http://0.0.0.0:3000/v1/users

Run Load

If you want to run a little load on the service you can use hey.

$ hey -H "Authorization: Bearer ${TOKEN}" -c 100 -n 10000 http://0.0.0.0:3000/v1/users

09: View Traces

If you want to see a few of the traces generated.

http://localhost:9411/zipkin/

Clone this wiki locally