TDM 40200: Project 14 — 2023

Motivation: Containers are everywhere and a very popular method of packaging an application with all of the requisite dependencies. In the previous series of projects you’ve built a web application. While right now it may be easy to share and run your application with another individual, as time goes on and packages are updated, this is less and less likely to be the case. Containerizing your application ensures that the application will have the proper versions of the proper packages available in the proper location to run.

Context: This is a final of a series of projects focused on containers. The end goal of this series is to solidify the concept of a container, and enable you to "containerize" the application you’ve spent the semester building. You will even get the opportunity to deploy your containerized application!

Scope: Python, containers, UNIX

Learning Objectives
  • Improve your mental model of what a container is and why it is useful.

  • Use docker to build a container image.

  • Understand the difference between the ENTRYPOINT and CMD commands in a Dockerfile.

  • Use docker to run a container.

  • Use docker to run a shell inside of a container.

Make sure to read about, and use the template found here, and the important information about projects submissions here.

Questions

Question 1

Please be sure to start this project early in the week so resources are not constrained on Friday.

If at any time you get stuck on this project, please create a Piazza post. We are happy to help!

The ultimate goal of this project is to take your containerized web application from the previous project, and deploy it on Geddes, Purdue’s Kubernetes cluster. In order to save you some time, we already performed operations akin to the following. These images are already available for you to use with this project.

# change the name/tag of the previously tagged "client" image to the fully qualified tag
docker tag client geddes-registry.rcac.purdue.edu/tdm/student-client:0.0.1
docker tag server geddes-registry.rcac.purdue.edu/tdm/student-server:0.0.1

# you can see that they are different now
docker images

# login to the registry
docker login geddes-registry.rcac.purdue.edu

# push the images to the registry
docker push geddes-registry.rcac.purdue.edu/tdm/student-client:0.0.1
docker push geddes-registry.rcac.purdue.edu/tdm/student-server:0.0.1

Login to geddes-registry.rcac.purdue.edu and verify that the images are there (they are there, we put them there). When you find the images, take a screenshot and include it in your submission.

Items to submit
  • Code used to solve this problem.

  • Output from running the code.

Question 2

The rest of this project will be performed using a web browser and geddes.rcac.purdue.edu, and that is it! It should be pretty quick! You just have to follow the instructions!

First thing is first. We need to create a place where we can store our imdb.db database that is persistent. You can imagine this as a thumb drive with our imdb.db file on it that we plug into our container and it appears at /data/imdb.db. If our container restarts, or is redeployed, we can just plug our thumb drive into that database with no data lost.

Okay, great. To do this in Kubernetes, we need to create a persistent volume claim.

  1. Click on Storage in the left hand menu.

  2. Click on PersistentVolumeClaims in the left hand menu.

  3. Click the large blue "Create" button in the top right.

  4. Fill out "Name" with yourname where you replace yourname with your actual name.

  5. Select "geddes-standard-multinode" for Storage Class.

  6. Write "15" in the Request Storage field.

  7. Click the blue "Create" button.

Take a screenshot that shows your claim named yourname under the "tdm-students" namespace. Include this screenshot in your submission.

Okay okay, with all of that being said, we will not be using this for the project. We don’t want you to worry about transferring the 10 GB database to this filestore. Instead, in the next question, when you are creating your deployment, you will select one we have that is already pre-loaded with the database.

Items to submit
  • Code used to solve this problem.

  • Output from running the code.

Question 3

Next, it is time to deploy your server.

  1. Click on Workload in the left hand menu.

  2. Click the large blue "Create" button in the top right.

  3. Click on "Deployment" from the 5 shown options.

  4. Fill out "Name" with tdm-yourname-server where you replace yourname with your actual name.

  5. Type "geddes-registry.rcac.purdue.edu/tdm/student-server:0.0.1" in the "Container Image" field.

  6. Click on the "Labels & Annotations" tab.

  7. Click the "Add Label" button under the "Pod Labels" section.

  8. Use the key tdm-yourname-server-label and value tdm-yourname-server-label where you replace yourname with your actual name.

  9. Click on the Resources tab.

  10. Put 200 in the CPU Reservation and CPU Limit fields.

  11. Put 1000 in the Memory Reservation and Memory Limit fields.

  12. Click on the Storage tab.

  13. Click on the Add Volume drop down.

  14. Select "Persistent Volume Claim" from the list. Not "Create Persistent Volume Claim" — we already did that.

  15. Name the volume yourname-vol, and select kevin from the Persistent Volume Claim dropdown.

    kevin is the volume that already has our database preloaded.

  16. Type /data and nothing (leave it blank) for Mount Point and Sub Path in Volume, respectively.

  17. Click the big blue "Create" button in the bottom right.

Items to submit
  • Code used to solve this problem.

  • Output from running the code.

Question 4

Next, it is time to deploy your client.

  1. Click on Workload in the left hand menu.

  2. Click the large blue "Create" button in the top right.

  3. Click on "Deployment" from the 5 shown options.

  4. Fill out "Name" with tdm-yourname-client where you replace yourname with your actual name.

  5. Type "geddes-registry.rcac.purdue.edu/tdm/student-client:0.0.1" in the "Container Image" field.

  6. Click on "Add Variable" in the "Environment Variables" section.

  7. Add the Variable Name "SERVER_HOST" and Value "yourname-server.tdm-students.geddes.rcac.purdue.edu".

    Replace "yourname" with your actual name. Do not put "tdm-yourname-server" in the value field — we do not want to target the server container itself, but rather the server’s service (which have not yet created).

    The client container looks for a "SERVER_HOST" environment variable so we know where to make requests to.

  8. Click on the "Labels & Annotations" tab.

  9. Click the "Add Label" button under the "Pod Labels" section.

  10. Use the key tdm-yourname-client-label and value tdm-yourname-client-label where you replace yourname with your actual name.

  11. Click on the Resources tab.

  12. Put 100 in the CPU Reservation and CPU Limit fields.

  13. Put 1000 in the Memory Reservation and Memory Limit fields.

  14. Click the big blue "Create" button in the bottom right.

Items to submit
  • Code used to solve this problem.

  • Output from running the code.

Question 5

Next, it is time to setup the services for your server and client. Specifically you will create a load balancer service for each of your server and client. These load balancers will map a given URL to a specific container. We will be setting up a service to map yourname-server.tdm-students.geddes.rcac.purdue.edu to your server container, and yourname.tdm-students.geddes.rcac.purdue.edu to your client container.

Ultimately, you will be able to open a browser and type in yourname.tdm-students.geddes.rcac.purdue.edu/people/nm0000148 and see the client container’s web interface!

  1. Click on "Services" under "Service Discovery" in the left hand menu.

  2. Click on the large blue "Create" button in the top right.

  3. Click on "Load Balancer" from the 5 shown options.

  4. For Name, type in yourname-server where you replace yourname with your actual name.

  5. Put anything you’d like in the "Port Name" field.

  6. Put 7777 for both the Listening Port and Target Port.

  7. Click on the "Selectors" tab.

  8. Put tdm-yourname-server-label in the "Key" field and tdm-yourname-server-label in the "Value" field. Once typed in, you should see a green box popup showing that it was able to identify the container you are targeting — our server container.

  9. Click on the "Labels & Annotations" tab.

  10. Click on "Add Annotation".

  11. Put metallb.universe.tf/address-pool in the "Key" field and geddes-public-pool in the "Value" field.

    This annotation uses the metallb library to tell the load balancer to use the geddes-public-pool address pool. This is the pool that research computing has configured to expose to the world, rather than just the Purdue network. So this means you can navigate to yourname.tdm-students.geddes.rcac.purdue.edu from your home computer, without being on Purdue’s VPN. If we instead used geddes-private-pool, you would only be able to access the service from within Purdue’s network.

  12. Click on the large blue "Save" button in the bottom right.

Your server should now be running at yourname-server.tdm-students.geddes.rcac.purdue.edu:7777. Congratulations!

Next, we want to create a service for the client.

  1. Click on "Services" under "Service Discovery" in the left hand menu.

  2. Click on the large blue "Create" button in the top right.

  3. Click on "Load Balancer" from the 5 shown options.

  4. For Name, type in yourname where you replace yourname with your actual name.

  5. Put anything you’d like in the "Port Name" field.

  6. Put 80 for the Listening Port and 8888 for the Target Port.

    This makes it so you do not need to navigate to yourname.tdm-students.geddes.rcac.purdue.edu:8888 to access the client, but rather just yourname.tdm-students.geddes.rcac.purdue.edu. By default, when the port isn’t specified, traffic is sent to port 80. Then, the traffic sent to port 80 is forwarded to port 8888 on our container.

  7. Click on the "Selectors" tab.

  8. Put tdm-yourname-client-label in the "Key" field and tdm-yourname-client-label in the "Value" field. Once typed in, you should see a green box popup showing that it was able to identify the container you are targeting — our client container.

  9. Click on the "Labels & Annotations" tab.

  10. Click on "Add Annotation".

  11. Put metallb.universe.tf/address-pool in the "Key" field and geddes-public-pool in the "Value" field.

  12. Click on the large blue "Save" button in the bottom right.

Finally, it is time to see if everything has been deployed! Open a browser and navigate to yourname.tdm-students.geddes.rcac.purdue.edu/people/nm0000148. If you see some sort of error message having to do with security, please make sure you are using http instead of https. If your browser keeps changing http to https, you can make it work by installing Firefox. Once installed, click on the menu, then Settings, then Privacy and Security, then "Don’t enable HTTPS-Only Mode". Next, in the URL, type about:config, search for "browser.fixup.fallback-to-https", and set it to "false". Restart Firefox completely, and try navigating to yourname.tdm-students.geddes.rcac.purdue.edu/people/nm0000148 again. It may take 30 seconds or so for the page to load — we are using very few resources!

Once you see the proper web page, take a screenshot for your final submission. Make sure to include the URL in the screenshot!

Please make sure to follow the steps below to free up resources for your fellow students! Thank you!

Finally, once you’ve acquired your screenshot, please delete your deployments. You can do this as follows.

  1. Click on "Deployments" under "Workloads" in the left hand menu.

  2. Click on the three dots to the right of your deployment. Make sure it is YOUR deployment.

  3. Click on "Delete".

  4. Click on "Services" under "Service Discovery" in the left hand menu.

  5. Click on the three dots to the right of your service. Make sure it is YOUR service.

  6. Click on "Delete".

Items to submit
  • Code used to solve this problem.

  • Output from running the code.

Please make sure to double check that your submission is complete, and contains all of your code and output before submitting. If you are on a spotty internet connection, it is recommended to download your submission after submitting it to make sure what you think you submitted, was what you actually submitted.

In addition, please review our submission guidelines before submitting your project.