sudo make allBuild the images and spin up the containers:
sudo docker-compose up -d --build(Optional) Recreate the database:
sudo docker-compose exec server python manage.py recreate_dbTest it out at:
curl http://localhost:8080/hello/user -d '{"dateOfBirth":"2018-08-12"}' -H "Content-Type: application/json" -X PUT -v
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> PUT /hello/user HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 28
>
* upload completely sent off: 28 out of 28 bytes
< HTTP/1.1 204 NO CONTENT
< Server: gunicorn/19.9.0
< Date: Mon, 12 Aug 2019 11:47:20 GMT
< Connection: close
< Content-Type: application/json
< Access-Control-Allow-Origin: *
<
* Closing connection 0curl http://localhost:8080/hello/user -v
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /hello/user HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: gunicorn/19.9.0
< Date: Mon, 12 Aug 2019 11:48:08 GMT
< Connection: close
< Content-Type: application/json
< Content-Length: 44
< Access-Control-Allow-Origin: *
<
{"message": "Hello, user! Happy birthday!"}
* Closing connection 0- http://localhost:8080/hello/user
- http://localhost:8080/healthz
- http://localhost:8080/readiness
- http://localhost:8080/metrics
Stop and remove containers, networks, images, and volumes:
sudo docker-compose down- Install Google Cloud SDK Command-line interface for Google Cloud Platform products and services.
- You need to configure both auth application-default login and auth login
- After installing Google Cloud SDK you should have kubectl configured.
Once you authenticated successfully, credentials are preserved. To see a list of components that are available and currently installed, run gcloud components list
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Components │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬──────────┤
│ Status │ Name │ ID │ Size │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼──────────┤
│ Installed │ Cloud Storage Command Line Tool │ gsutil │ 3.6 MiB │
│ Installed │ gcloud Alpha Commands │ alpha │ < 1 MiB │
│ Installed │ gcloud Beta Commands │ beta │ < 1 MiB │
│ Installed │ kubectl │ kubectl │ < 1 MiB │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴──────────┘gcloud auth application-default login; gcloud auth login;Start the cluster:
gcloud beta container clusters create "standard-cluster-2" \
--machine-type "n1-standard-2" --image-type "COS" \
--disk-type "pd-standard" --disk-size "100" \
--preemptible --num-nodes "3" \
--addons HorizontalPodAutoscaling,HttpLoadBalancingCreate the volume claim:
kubectl apply -f ./kubernetes/persistent-volume-claim.ymlCreate the secret object:
kubectl apply -f ./kubernetes/secret.ymlProduction HA-Postgres could be installed via helm chart, but we will use simplified deployment version
Create deployment:
kubectl create -f ./kubernetes/postgres-deployment.ymlCreate the service:
kubectl create -f ./kubernetes/postgres-service.ymlCreate the deployment:
kubectl create -f ./kubernetes/flask-deployment.yml(Optional) Drop all entries in the database and recreate tables:
kubectl exec deployment.apps/server --stdin --tty -- python manage.py recreate_dbCreate the service:
kubectl create -f ./kubernetes/flask-service.ymlTry it out:
export EXTERNAL_IP=`kubectl get services server --output jsonpath='{.status.loadBalancer.ingress[0].ip}'`
curl http://$EXTERNAL_IP/hello/user -d '{"dateOfBirth":"2018-08-12"}' -H "Content-Type: application/json" -X PUT -v
curl http://$EXTERNAL_IP/hello/user -v
curl http://$EXTERNAL_IP/healthz -v
curl http://$EXTERNAL_IP/metrics -v
curl http://$EXTERNAL_IP/readiness -vTo remove all deployments:
kubectl delete -f kubernetes/