西维蜀黍

【Kubernetes】Kubelet 和 Pod

Kubernetes

kubernetes 是一个分布式的集群管理系统,在每个节点(node)上都要运行一个 worker 对容器进行生命周期的管理,这个 worker 程序就是 kubelet

简单地说,kubelet 的主要功能就是定时从某个地方获取节点上 Pod / Container 的期望状态(运行什么容器、运行的副本数量、网络或者存储如何配置等等),并调用对应的容器平台接口达到这个状态。

集群状态下,kubelet 会从 master 上读取信息,但其实 kubelet 还可以从其他地方获取节点的 pod 信息。目前 kubelet 支持三种数据源:

  ...


【Linux】查看 Log

Log Files

  • /var/log/syslog or /var/log/messages: general messages, as well as system-related information. Essentially, this log stores all activity data across the global system.

  • /var/log/auth.log or /var/log/secure: store authentication logs, including both successful and failed logins and authentication methods. Again, the system type dictates where authentication logs are stored; Debian/Ubuntu information is stored in /var/log/auth.log, while Redhat/CentrOS is stored in /var/log/secure.

  • /var/log/boot.log: a repository of all information related to booting and any messages logged during startup.

  • /var/log/maillog or var/log/mail.log: stores all logs related to mail servers, useful when you need information about postfix, smtpd, or any email-related services running on your server.

  • /var/log/kern: stores Kernel logs and warning data. This log is valuable for troubleshooting custom kernels as well.

  • /var/log/dmesg: messages relating to device drivers. The command dmesg can be used to view messages in this file.

  • /var/log/faillog: contains information all failed login attempts, which is useful for gaining insights on attempted security breaches, such as those attempting to hack login credentials as well as brute-force attacks.

  • /var/log/cron: stores all Crond-related messages (cron jobs), such as when the cron daemon initiated a job, related failure messages, etc.

  • /var/log/messages : General message and system related stuff

  • /var/log/auth.log : Authenication logs

  • /var/log/kern.log : Kernel logs

  • /var/log/cron.log : Crond logs (cron job)

  ...


【Lock】锁(Lock)/ Mutex

Lock / Mutex

In computer science, a lock or mutex (from mutual exclusion) is a synchronization primitive: a mechanism that enforces limits on access to a resource when there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy, and with a variety of possible methods there exists multiple unique implementations for different applications.

  ...


【Operating System】进程 - 进程通讯 - Monitor

Monitor

Definition1

由于信号量和互斥锁可能会导致**死锁(deadlock)**问题,因此,在实际生产中使用信号量和互斥锁必须非常小心。

为此,Brinch Hansen 和 Hoare 提出了一个更高层(higher-level)的同步原语(primitive),以实现互斥(mutual exclusion),称为管程(Monitor)。管程(Monitor) 从本质来说是一个程序集、变量和数据结构集合。

管程要求:在任一时刻只有一个进程能在管程中处于活跃状态(active)。

具体来说,当一个进程调用管程程序时, 管程程序会首先检查当前是否有其他进程在监视器中处于活跃状态。如果有,这个进程会进入阻塞状态直到其他进程离开了监视器;如果没有其他进程正在使用监视器,这个进程就可以使用监视器。

编译器会具体负责管程机制如何具体实现(虽然通常的方法是通过互斥锁)。因此,对程序员而言,我们只需要知道管程机制能够保证互斥访问(mutual exclusion),即任一时刻只会有一个进程进入临界区。

Definition2

In concurrent programming (also known as parallel programming), a monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to wait (block) for a certain condition to become false.

Monitors also have a mechanism for signaling other threads that their condition has been met. A monitor consists of a mutex (lock) object and condition variables. A condition variable essentially is a container of threads that are waiting for a certain condition. Monitors provide a mechanism for threads to temporarily give up exclusive access in order to wait for some condition to be met, before regaining exclusive access and resuming their task.

Another definition of monitor is a thread-safe class, object, or module that wraps around a mutex in order to safely allow access to a method or variable by more than one thread.

The defining characteristic of a monitor is that its methods are executed with mutual exclusion: At each point in time, at most one thread may be executing any of its methods. By using one or more condition variables it can also provide the ability for threads to wait on a certain condition (thus using the above definition of a “monitor”). For the rest of this article, this sense of “monitor” will be referred to as a “thread-safe object/class/module”.

  ...


【Design Pattern】Concurrency - Active Object Pattern

ACTIVE OBJECT

Active Object is a concurrency pattern in which we try to separate the invocation of a method from its execution. Typically, an active object provides synchronous methods and executes the method calls in an asynchronous way. An active object usually has its own thread of control.

This pattern is useful in refactoring legacy projects by introducing concurrency capability.

The following class diagram shows the basic structure of this pattern.

The key elements in active object pattern are:

  • Proxy (or Client Interface) - A public method provided by active object to clients.
  • Dispatch Queue - A list of pending requests from clients.
  • Scheduler - Determines the order to execute the requests.
  • Result Handle (or Callback) - This allows the result to be obtained by proxy after a request is executed.
  ...