DevOps Lesson
import socket
# Change the following host and see what IP it prints!
host = "disneyplus.com"
ip = socket.gethostbyname(host)
print(ip)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
print("Successfully connected!")
Check-In
- What is an IP address? Answer: An address that is put in the browser. It is a numeric value assigned to a network device, and it is used for the identification and location of a network device.
- What is a TCP port? Answer: A transmission control protocal is a connection-oriented protocal. In networking, protocols are rules or standards that govern how data is transmitted between devices.
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
# Send a GET request to "/"
s.sendall(b"GET / HTTP/1.1\r\n\r\n")
# Recieve & print 2048 bytes of data
data = s.recv(2048)
print(data.decode())
import requests
# Change the URL to whatever you'd like
response = requests.get("https://disney.com")
print("Status code:", response.status_code)
print("Headers:", response.headers)
print("Response text:", response.text[:100])
# Add a line to print the "Content-Type" header of the response
# Try an image URL!
aws = "3.130.255.192"
response = requests.get("http://" + aws)
print(response.text)
Configuration
server {
// Listen on virtual "port 80"
listen 80;
listen [::]:80;
server_name 3.130.255.192;
location / {
// Inform server about original client
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
// Forward all requests transparently to the server running on our computer
proxy_pass http://localhost:9099;
}
}
Load Balancing
upstream example.com {
server server1.example.com;
server server1.example.com;
}
HTTP Headers
server {
add_header X-Cool-Header "I love APCSP!";
location /pages {
add_header X-Cooler-Header "This is my secret header!";
}
}
Check In
- Research 1 HTTP header and describe, in detail, its purpose.
-
This is an example of an HTTP header a user could include in their HTTP request:
-
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36
-
This header is very useful for the server that needs to respond to the request. Since the user sent this information along with the request, it gives much more helpful information that can help the server with things like compatiability, security, and analyitics.
- Write a line in a sample NGINX configuration that will add that specific header to the
/information
location
using your code/server from earlier, I can add a specific header to the '/information' location with this code
```nginx server { add_header X-Cool-Header "I love music!";
location /pages { add_header X-Cooler-Header "This is my secret header!"; }
location /information { add_header Shruthi-Header "This is cool"; } }
- Explain the purpose of the load balancing performed by NGINX
Load balancing by NGINX distributes network traffic among many servers/computers. This improves efficiency, reliability and availability of the application.
- Modify the following code block to obtain the value of the secret header on
/products
of the AWS site
import requests
aws = "3.130.255.192"
response = requests.get("http://" + aws + "/products")
secret_header = response.headers.get('X-Cooler-Header')
print("The secret header is:", secret_header)
CORS Hacks
- Explain what CORS is and what it stands for
Answer: CORS stands for Cross-Origin Resource Sharing. It is a system, consisting of transmitting HTTP headers, that determines whether browsers block frontend JavaScript code from accessing responses for cross-origin resquests.
- Describe how you would be able to implement CORS into your own websites
Answer: To do this, open the server/index. js file and modify it to look like the following: const express = require("express"); const debug = require("debug")("server"); const app = express(); const port = process.
- Describe why you would want to implement CORS into your own websites
Answer: CORS allows more freedom and functionality than purely same-origin requests, but is more secure than simply allowing all cross-origin requests.
- How could use CORS to benefit yourself in the future?
Answer: I could use CORS to benefit myself in the future by being free to go to a restuarant with just my brother for dinner.
Total: 0.2 points
KASM Hacks
- What is the purpose of "sudo" when running commands in terminal?
Answer: The purpose of "sudo" when running commands in terminal is to get permission to run those commands.
- What are some commands which allow us to look at how the storage of a machine is set up as?
Answer: One of the commands which allows us to look at how the storage of a machine is set up as is df -H.
- What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
Answer: Some alternatives to running "curl -O" are to manually download the zip file using "wget" or to download and transfer it through something like Google-Drive.
- What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
-
Checking for system requirements
-
Downloading necessary files
-
Setting up environment
-
Installing necessary packages or libraries
"install.sh" is called to make the the installation process easier and more likely to be sucessful.
- Explain in at least 3-4 sentences how deploying KASM is related to/requires other topics talked about in the lesson and/or potential ways to add things mentioned in the lesson to this guide.
Answer: Deploying KASM, the container-based streaming service, requires several components such as headers, NGINX, load balancing, configuration, DNS, and CORS. Headers are important for configuring security settings and enabling CORS for KASM. NGINX is used as a reverse proxy to handle incoming web traffic and load balancing is necessary for distributing the traffic among multiple server instances running KASM. Configuration is required to set up the KASM service and define the specific settings for the environment in which it will run.
Total: 0.2 points