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.

  1. Open the milestone in GitHub Codespaces. Make sure it’s the milestone release.

  2. Check mysite/mysite/settings.yaml. Verify that the CSRF_TRUSTED_ORIGINS variable is set as shown above.

  3. 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.

  4. Compare the secrets deployment/secret.yaml to the settings in values-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).

  5. Start minikube

    $ minikube start
    
  6. Install the Postgres chart:

    $ helm install postgres oci://registry-1.docker.io/bitnamicharts/postgresql \
        --values deployment/values-postgres.yaml 
    
  7. 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 
    
  8. Initialize database.

    $ kubectl exec --stdin --tty pod/mysite-pod -- python manage.py migrate 
    $ kubectl exec --stdin --tty pod/mysite-pod -- python manage.py createsuperuser
    

    Error

    Verify that the database has not previously been initialized and create a new superuser account.

  9. 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.

  10. Take a screenshot of the index page showing the student and site names.

Requirements#

  1. A Deployment definition for Django that includes:

    1. Reasonable resource requests:

      1. At least 250m but not more than 1000m CPUs

      2. At least 128Mi of memory but not more than 1Gi of memory

    2. A health check

  2. A values-postgres.yaml file with Postgres settings

  3. You must REMOVE:

    1. deployment/pod.yaml - Replace this with a Deployment

    2. deployment/pvc.yaml - The Postgres chart contains the storage for your application1

  4. A Service definition for Django with type LoadBalancer

  5. Your application uses the Postgres database

Submit#

  1. Tag this milestone milestone-13.x.

  2. A URL to your release. It should look like this:

    https://github.com/your-name/your-cis-92-repo/releases/tag/milestone-13.1