Featured image of post Interview | Baidu Information Security Operations

Interview | Baidu Information Security Operations

Possible Pod Phases

Pod Phase

  • Running
  • Succeeded (Job completion, CronJob completion)
  • Failed (Program crash, container startup failure)
  • Pending (Resource shortage, NodeSelector no match, slow image pull)
  • Unknown (kubelet cannot report status, node offline, network interruption)

Creation/Deployment Related

  • ContainerCreating (Container is being created, pulling image)
  • PodInitializing (Container is initializing, executing init container)
  • ImagePullBackOff (Image pull failed, e.g., authentication issue, image does not exist)
  • ErrImagePull (Same as above, occurs earlier than BackOff)

Abnormalities During Runtime

  • CrashLoopBackOff (After the container crashes, kubelet will restart the container based on the backoff strategy, default is 10s later)
  • OOMKilled (Container memory exceeds the limit and is forcibly killed by kubelet)
  • BackOff (After multiple failures, enter the backoff state, such as init container failure)
  • CrashLoopBackOff (Main container keeps crashing and restarting)
  • CreateContainerConfigError (Container creation configuration error, such as a non-existent mounted volume)
  • Error (Container exits with a non-zero exit code, but may not trigger failure due to restart policy)

Termination/Completion

  • Terminating (Container is terminating, such as deleting pod)
  • Completed (Container exits normally, such as the main container exits)
  • Failed (Container exits with a non-zero exit code and the restart policy is Never)

Alert Architecture

Due to the involvement of the company’s alert system, it cannot be directly displayed.

Difference Between Counter and Gauge? What Scenarios to Use Counter

Counter

  • Only increments
  • Resets to zero after process restart
  • qps, error, data processing volume (per item/package/byte), retry count

Gauge

  • Can increment or decrement
  • Inventory values of Redis/Kafka/queue, cpu/memory, online number of people

Difference Between 502 and 504

  • 502 Gateway Error, usually the backend service returns an invalid response (such as returning HTML instead of JSON)
  • 504 Gateway Timeout, usually the backend service response time exceeds the gateway timeout time

IP Address Range of 192.168.1.0/25

There are 2^7 - 2 = 126 IP addresses in total 000 0000 192.168.1.1~192.168.1.126

192.168.1.127 is a broadcast address 192.168.1.128 is the subnet mask

How to Allow Port 80 on a Single Machine and Deny All Other Ports

iptables

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Allow localhost
sudo iptables -A INPUT -i lo -j ACCEPT
# Allow established connections
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow port 80
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# Deny all other ports
sudo iptables -P INPUT DROP
# Save rules
sudo service iptables save

Using Decorators in Python to Count Function Execution Time

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import time
from functools import wraps

def timer_decorator(func):
    @wraps(func)  # Preserve the original function's metadata
    def wrapper(*args, **kwargs):
        start_time = time.perf_counter()  # High-precision timing starts
        result = func(*args, **kwargs)    # Execute the original function and get the result
        end_time = time.perf_counter()    # Timing ends
        elapsed = end_time - start_time
        print(f"Function {func.__name__} execution time: {elapsed:.4f} seconds")
        return result  # Return the result of the original function
    return wrapper


@timer_decorator
def add_numbers(a, b):
    time.sleep(0.5)  # Simulate time-consuming operation
    return a + b

# Call the function, automatic timing
sum_result = add_numbers(3, 4)
print(f"Calculation result: {sum_result}")
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy 🚀
Published: 58 Posts  |  Total Views: ... views
Uptime: ...  |  Site Visits: ... views