13. A Scalable Application#
Accomplish this milestone by taking your application from the 10. A Complete Application milestone and making it scalable. A scalable application keeps data in a separate database backend and can scale up and down to handle traffic. To the end user there won’t be change in the application, but the difference is huge. In a business setting scalable applications make full and effective use of cloud resources by meeting demand as it changes, keeping your site available during peak times and costing less during slow times.
Remove the Pod and PVC#
Your application should be using a Deployment
resource instead of just a Pod
. There’s no reason to keep the Pod
definition around anymore. Also, you’re using Postgres now so there should be no data in the PersistentVolumeClaim
in deployment/pvc
. Delete them both before you create the release on GitHub. That makes it much simpler to deploy your app with one command. Remove the deployment/pod.yaml
and deployment/pvc.yaml
files.
Fix the CSRF Setting#
There is a setting in the mysite/mystite/settings.py
file that has been preventing reviewers from logging in to a reviewee’s site. To accomplish this milestone you have to change the setting and rebuild the application container. Make sure the following setting is present:
CSRF_TRUSTED_ORIGINS = ['https://*.cloudshell.dev',
'https://*.github.dev',
'https://localhost:8000']
Note
There should already be a CSRF_TRUSTED_ORIGINS
setting. Overwrite the existing one.
Release#
Before you submit this milestone make a GitHub release named milestone-13.x
. This release requires changes to your application and its Dockerfile
.
Test Procedure#
This is a release of what should be a complete and working and scalable application. Keep that in mind when you’re testing it. An end user should be able to apply the resources, create a superuser and go! To test you’ll use minikube
which is a stripped down Kubernetes that is used for debugging locally.
Only Test a Release
It’s essential to only test the code snapshot in a release, not the main
branch. Your reviewee should have posted a URL like this:
https://github.com/your-name/your-cis-92-repo/releases/tag/milestone-13.1
Notice that it ends with releases/tag/mileston-13.1
. If it doesn’t look like that they posted a link to the main
branch. Stop and let them know.
Open the milestone in GitHub Codespaces. Make sure it’s the milestone release.
Check
mysite/mysite/settings.yaml
. Verify that theCSRF_TRUSTED_ORIGINS
variable is set as shown above.Open
deployment/config.yaml
and verify that the following settings are present:Variable
Value
POSTGRES_HOSTNAME
postgres-postgresql
Error
If any are missing or set incorrectly send a report with the specific variable names and the correct value.
Compare the secrets
deployment/secret.yaml
to the settings invalues-postgres.yaml
. The database settings must match:secret.yaml
values-postgres.yaml
POSTGRES_PASSWORD
auth.username
POSTGRES_USER
auth.password
POSTGRES_DB
auth.database
Error
If any of the settings don’t match send a report telling the reviewee which one(s).
Start
minikube
$ minikube start
Install the Postgres chart:
$ helm install postgres oci://registry-1.docker.io/bitnamicharts/postgresql \ --values values-postgres.yaml
Apply all resources in the
deployment
directory.$ kubectl apply -f deployment/
Note
It takes applications a little while to get ready. Check that it’s working by running:
$ kubectl get all
Initialize database.
$ kubectl exec --stdin --tty deployment.apps/mysite-deployment -- python manage.py migrate $ kubectl exec --stdin --tty deployment.apps/mysite-deployment -- python manage.py createsuperuser
Error
Verify that the database has not previously been initialized and create a new superuser account.
Login using the new account using a forwarded port.
$ kubectl port-forward svc/mysite-svc 8000:80
Error
Make sure all of the pages of the app work and that the student and site names match the configuration.
Take a screenshot of the index page showing the student and site names.
Requirements#
A
Deployment
definition for Django that includes:Reasonable resource requests:
At least 250m but not more than 1000m CPUs
At least 128Mi of memory but not more than 1Gi of memory
A health check
A
values-postgres.yaml
file with Postgres settingsYou must REMOVE:
deployment/pod.yaml
- Replace this with a Deploymentdeployment/pvc.yaml
- The Postgres chart contains the storage for your application1
A
Service
definition for Django with typeLoadBalancer
Your application uses the Postgres database
Submit#
Tag this milestone
milestone-13.x
.A URL to your release. It should look like this:
https://github.com/your-name/your-cis-92-repo/releases/tag/milestone-13.1