Understanding Kubernetes Scheduler

1. Overview The kube-scheduler is the matchmaker of Kubernetes. Its job is to find the best Node for every newly created Pod. It considers: Resource availability: CPU/Memory/Storage. Affinity and Anti-affinity: Do Pods want to be together or apart? Taints and Tolerations: Should a Node repel certain Pods? Priorities: Which Pod is more important? 2. Resource Management Inside the resources section of a PodSpec: Requests: What the container needs. The scheduler uses this value to find a node. Limits: What the container is allowed to use. Enforced at runtime by the Cgroup. LimitRange: A cluster resource to enforce default, min, and max requests/limits for all Pods in a namespace. ...

November 29, 2023 · 2 min

Understanding Kubernetes Etcd

1. Overview etcd is a distributed, reliable key-value store for the most critical data of a distributed system. Based on the Raft consensus algorithm, it provides strong consistency and high availability. In Kubernetes, etcd is the single source of truth. It stores: Cluster configuration (API objects). Actual state info (Which pods are running where). Service discovery and config sharing. Backups and recovery data. 2. Basic Operations (etcdctl) Member List: $ etcdctl member list Storing Data: $ etcdctl put key value Retrieving Data: $ etcdctl get key Watching: $ etcdctl watch key (Triggers a notification when the key changes). 3. Leases and TTL A Lease is a mechanism for expiring keys after a set time. ...

November 25, 2023 · 2 min

Understanding Kubernetes ConfigMap

Local Setup (Docker Desktop) If you are using Docker Desktop and Kubernetes won’t start, common fixes include: Adding Chinese images mirrors. Using helper scripts to pull the required K8s images locally. Verify your setup: $ kubectl get nodes $ kubectl cluster-info Pods and Services A Pod is the smallest deployable unit. Let’s start an Nginx deployment: $ kubectl create deployment nginx --image=nginx $ kubectl expose deployment nginx --port=80 --type=LoadBalancer $ curl 127.0.0.1:80 ConfigMap: Decoupling Config from Code A ConfigMap stores non-confidential data in key-value pairs. This allows you to change environment variables or configuration files without rebuilding the container image. ...

November 16, 2023 · 2 min

Prompt Engineering Tips for Large Language Models

Overview Some time ago, I took a course on Prompts at DeepLearning.ai. I found it very beneficial, so I’m summarizing and sharing my learning notes here, hoping to help everyone. Why learn Prompts? Because in the future AIGC era, learning effective Prompt cues to effectively utilize AI to complete repetitive work will be one of the essential skills for everyone. The following is my personal summary after completing this course: ...

June 5, 2023 · 12 min

Understanding and Applying Java Generics

1. Overview Generics sanitize your code by providing: Safety: Compile-time type checking. Reusability: Using <T> for generic structures. Cleanliness: Reducing boilerplate casting. Java generics are implemented via Type Erasure, meaning the type information exists only during compilation to ensure backward compatibility. 2. Basic Evolution Concrete Types: IntList only handles integers. Object Container: ObjectList handles everything but requires non-safe casting. Generics: GenericList<T> handles everything with full type safety. 3. Tuples: Simple Data Objects When you need to return multiple values of different types without a dedicated POJO: ...

May 24, 2023 · 2 min

Understanding and Applying Java Reflection

1. Overview Reflection allows a Java program to inspect or manipulate its own internal structure at runtime. It can access class names, fields, methods, and constructors without knowing them at compile time. 2. Why Reflection? Dynamic Loading: Class.forName(name) allows loading plugins or drivers at runtime. Dynamic Invocation: Frameworks like Spring use it to call methods on Bean instances. Generic Inspection: Writing code that can work with any object (e.g., serializing a JSON string). 3. Usage Scenarios Frameworks: Spring (Dependency Injection), JUnit (finding @Test methods). ORM: Hibernate/MyBatis mapping DB rows to POJO fields. Dynamic Proxy: Routing method calls at runtime. Unit Testing: Accessing private fields or methods for validation. 4. The Class Object The java.lang.Class object is the entry point. Ways to get it: ...

May 21, 2023 · 2 min

Reflections on Java Exception Handling

1. Classification of Java Exceptions Java exceptions are basically divided into two categories: Checked Exceptions and Unchecked Exceptions (Runtime Exceptions). Checked Exceptions These are exceptions that the compiler forces you to handle (either via try-catch or throws). They usually represent external factors that the program cannot control, such as a file not being found or a network interruption. Unchecked Exceptions (Runtime Exceptions) These occur during the execution of the program, such as NullPointerException, ArrayIndexOutOfBoundsException, or IllegalArgumentException. They usually indicate programming errors or logic flaws. ...

May 18, 2023 · 2 min

Guide to java.nio.file Library in Java

Introduction Before Java 7, file handling was primarily done through java.io.File, which lacked support for symbolic links, modern file systems, and efficient recursive operations. The java.nio.file package (NIO.2) introduced in Java 7 solved these issues with a more comprehensive and powerful API. Core Components 1. Path The Path interface represents a hierarchical path to a file or directory. Unlike File, it is system-independent. Path path = Paths.get("data", "logs", "app.log"); // On Windows: data\logs\app.log // On Linux: data/logs/app.log 2. Files Utility The Files class contains static methods for almost any file operation: ...

May 9, 2023 · 2 min

Several Reference Suggestions for Improving Code Quality

Unit Testing What is Unit Testing? Unit testing usually refers to testing a single function or method. The purpose of unit testing is to verify whether the behavior of each unit meets expectations and to quickly detect any potential problems when modifying the code. By writing test cases, we can verify whether these modules produce the correct output for specific inputs. The goal is to ensure that each module runs normally in various situations. ...

April 25, 2023 · 4 min

Redis Stream: A Better Message Queue

Requires Redis 5.0.0+ Overview Redis Stream is a powerful log-like data structure. While Redis already had Lists and Sets, Stream was built specifically for high-throughput, persistent messaging with features like Consumer Groups and Acknowledged delivery. Core Commands XADD: Appending Data XADD my-stream * name "John" age 30 * tells Redis to auto-generate the ID. Returns an ID like 1681138020163-0 (Timestamp-Sequence). XLEN: Getting Length Returns the number of messages in the stream. ...

April 17, 2023 · 2 min