wilh.net Linux and DevOps Wiki

website·Indexed 29 days ago

https://wilh.net

A technical knowledge base covering Linux fundamentals, network configuration, and DevOps tools including Kubernetes architecture, Ansible configuration management, and Nginx performance features.

Tokens
6.6K
Snippets
39
Records
53
Agent score
49%

What's inside wilh.net

  1. Overview of Nginx core features and capabilities

    Nginx is a high-performance, lightweight web server and reverse proxy designed to handle large volumes of concurrent connections using an event-driven architecture. Key capabilities include:

    • Performance & Efficiency: Low CPU and memory footprint, making it suitable for resource-constrained environments.
    • High Availability: Supports hot deployment, allowing configuration updates and software upgrades without stopping the service.
    • Extensibility: Modular design that supports third-party modules for custom functionality.
    • Core Functionalities: Beyond serving static content, it provides reverse proxying, load balancing, caching acceleration, SSL acceleration, and WebSocket support.
    • Management: Features a clear configuration structure with a wide range of directives for flexible system administration.
  2. Understand Kubernetes core features

    Kubernetes provides several automated mechanisms to manage containerized applications:

    • Automated Rollouts and Rollbacks: Gradually deploys changes to applications or configurations while monitoring health to prevent total service outage; rolls back automatically if issues occur.
    • Service Discovery and Load Balancing: Assigns unique IP addresses and DNS names to containers and balances traffic across them without requiring application changes.
    • Storage Orchestration: Automatically mounts storage systems (local, public cloud like GCP/AWS, or network storage like NFS, iSCSI, Gluster, Ceph, Cinder, Flocker).
    • Horizontal Scaling: Scales applications up or down via simple commands, UI, or automatically based on CPU usage.
    • Self-healing: Restarts failed containers, replaces and reschedules containers when nodes die, and kills containers that fail user-defined health checks.
    • Automated Bin Packing: Places containers based on resource requirements and constraints to optimize resource utilization.
    • Batch Execution: Manages batch and CI workloads, replacing failed containers as needed.
    • Dual-stack IPv4/IPv6: Assigns both IPv4 and IPv6 addresses to Pods and Services.
    • Secret and Configuration Management: Updates secrets and app configs without rebuilding container images.
  3. Understand Kubernetes cluster architecture

    Kubernetes is a distributed system consisting of two primary node types:

    1. Master Nodes (Control Plane): Act as the management headquarters. Key components include:

    • API Server: The entry point for all requests.
    • Scheduler: Assigns Pods to specific worker nodes based on algorithms.
    • Controller-Manager: Manages cluster state, such as scaling containers.
    • Etcd: A distributed key-value store used to persist the cluster's state.

    2. Node Nodes (Worker/Minion): Host the actual application containers. Key components include:

    • Kubelet: The agent that ensures containers are running in a Pod.
    • Kube Proxy: Handles network proxying and load balancing.
    • Container Runtime: The software responsible for running containers (e.g., Docker).

    Add-ons: Optional but often necessary components such as Network plugins (Flannel, Calico, Cilium), Dashboard tools (KubeSphere), and Ingress controllers for Layer 7 proxying.

  4. Ansible system requirements and control node constraints

    Ansible requires an SSH environment for communication between the server and client. The control node must be a Unix-like system (Windows is not supported) and requires Python 2.7+ or Python 3.5+.
  5. Disable swap for Kubernetes nodes

    Kubernetes requires swap to be disabled for the kubelet to function correctly. This can be achieved by turning off swap immediately and removing the swap entry from /etc/fstab to ensure it remains disabled after reboot.
    # Method 1: Immediate disable and persist via fstab
    swapoff -a
    sed -i '/swap/s/^/#/' /etc/fstab
    
    # Method 2: Using systemd
    systemctl stop swap.img.swap
    systemctl mask swap.img.swap
    
    # Verify swap is disabled
    swapon -s
  6. Initialize environment for Kubernetes cluster deployment

    Before installing Kubernetes, ensure all nodes meet the following hardware and software requirements:

    • Hardware: Minimum 2 CPU cores and 2GB RAM per host.
    • OS: Minimal Linux installation supporting Kubernetes.
    • Network: Unique hostnames, MAC addresses, and product_uuids; ensure correct network configuration and connectivity between nodes.
    • Security/System:
      • Disable swap.
      • Disable SELinux.
      • Open required Kubernetes ports or disable firewalld/iptables.
    • Time: Configure correct timezone and time synchronization.
    • Optimization: Apply kernel parameter optimizations.
    • Access: SSH key-based authentication for all nodes (optional).
  7. Install cri-dockerd for Kubernetes container runtime

    Since Kubernetes removed direct support for Docker, cri-dockerd is used as an adapter to allow Kubernetes to use Docker as the container runtime. This involves installing the binary and configuring it as a systemd service.
    # Download and install binary
    wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.18/cri-dockerd-0.3.18.amd64.tgz
    tar xf cri-dockerd-0.3.18.amd64.tgz
    mv cri-dockerd/cri-dockerd /usr/local/bin/
    
    # Install systemd service and socket
    wget -O /lib/systemd/system/cri-docker.service https://raw.githubusercontent.com/Mirantis/cri-dockerd/refs/heads/master/packaging/systemd/cri-docker.service
    wget -O /lib/systemd/system/cri-docker.socket https://raw.githubusercontent.com/Mirantis/cri-dockerd/refs/heads/master/packaging/systemd/cri-docker.socket
    
    systemctl daemon-reload && systemctl enable --now cri-docker.service
    
    # Note: Edit /lib/systemd/system/cri-docker.service ExecStart for specific versions
    # Example for v1.34.1:
    # ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --pod-infra-container-image registry.aliyuncs.com/google_containers/pause:3.10
  8. Install Ansible on Ubuntu

    Install Ansible on Ubuntu by adding the official PPA repository to ensure the latest version is available.
    # Update software sources
    apt update
    apt install -y software-properties-common
    
    # Install Ansible PPA
    add-apt-repository --yes --update ppa:ansible/ansible
    
    # Install Ansible
    apt-get install ansible
    
    # Verify installation
    ansible --version
  9. Collect system information using the Setup module

    The setup module gathers facts (system properties) from remote hosts. If no arguments are provided, it retrieves all available facts. You can use the filter parameter with regular expressions to retrieve specific attributes.
    # Get all system properties
    ansible 10.0.0.15 -m setup
    
    # Get specific attribute: total memory in MB
    ansible 10.0.0.15 -m setup -a "filter=ansible_memtotal_mb"
    
    # Get specific attributes using a regex filter (e.g., network interface info)
    ansible 10.0.0.15 -m setup -a "filter=*ens*"
  10. Improve Ansible Playbook maintainability and reuse

    Use Roles to encapsulate common tasks (e.g., an Nginx role) for reuse across different Playbooks. For large Playbooks, break them into smaller files and use include_tasks or import_tasks to maintain a clear structure. Use ignore_errors or failed_when to handle expected failures without stopping the entire execution.
  11. Install Ansible from Git source

    Install Ansible by cloning the official GitHub repository and setting up the hacking environment.
    # Clone the repository
    mkdir /data/codes && cd /data/codes
    git clone https://githubfast.com/ansible/ansible.git
    cd ./ansible
    
    # Load environment configuration
    source ./hacking/env-setup
    
    # Verify version
    python3 bin/ansible --version
  12. Install Ansible on CentOS

    On CentOS/Rocky Linux, the EPEL repository provides ansible-core. For the full Ansible distribution (including community collections), installation via pip is recommended.
    # Install EPEL release
    yum update
    yum install epel-release
    
    # Install ansible-core
    yum install ansible-core
    
    # Verify installation
    rpm -q ansible-core