主页

Kubernetes Ingress Understanding

在 Kubernetes 中,Ingress 架构的精髓正是通过单一入口点管理所有入站流量,避免了为每个服务单独创建 LoadBalancer 的复杂性和成本。

graph TD
    %% 外部访问层
    A[External User] -->|HTTPS:443| B(Cloud Load Balancer)
    B -->|Routes to| C[Ingress Service<br>type: LoadBalancer]

    %% Ingress 控制层
    subgraph Ingress Namespace
        C --> D[Ingress Controller Pods<br>运行 Nginx]
        D -->|动态读取| E[Ingress Resource]
        D -->|监听变更| F[Kubernetes API]
    end

    %% 应用路由层
    E -->|路由规则 1| G[App Service A<br>type: ClusterIP]
    E -->|路由规则 2| H[App Service B<br>type: ClusterIP]

    %% 后端应用层
    G --> I[App Pods A]
    H --> J[App Pods B]

    %% 样式定义
    classDef external fill:#FFE7BA,stroke:#FFA940;
    classDef ingress fill:#B5F5EC,stroke:#13C2C2;
    classDef service fill:#FFD6E7,stroke:#FF85C0;
    classDef pod fill:#D6E4FF,stroke:#597EF7;

    class A,B external;
    class C,D,E ingress;
    class G,H service;
    class I,J pod;

阅读更多

Kubernetes Service Understanding

Kubernetes Service 理解

Kubernetes Service 与 Pod 的关系

Service 与 Pod 的关系是 Kubernetes 网络模型的核心,通过标签选择器(Label Selector) 建立动态关联:

graph LR
    Service -->|Label Selector| Pod1
    Service -->|Label Selector| Pod2
    Service -->|Label Selector| Pod3

    subgraph Pod Metadata
        Pod1[Pod] -->|Labels<br>app=frontend<br>env=prod| LabelSet
        Pod2[Pod] -->|Labels<br>app=frontend<br>env=prod| LabelSet
        Pod3[Pod] -->|Labels<br>app=frontend<br>env=prod| LabelSet
    end

阅读更多

Filebeat configuration on k8s

1. Background

The pods’ logs on AKS are collected by filebeat which is deployed as a DaemonSet on each node. The logs will be classified into different indices (business and non-business) based on the container name, and then rolled over to a new index when the index size exceeds 10GB or 1 day. The business logs are stored in Elasticsearch for 30 days, while the non-business logs are stored for 7 days.

阅读更多

Helm 命令

Helm 命令

Manage the releases of the charts that are deployed on the Kubernetes cluster. Examples:

# list the releases that are deployed in the current namespace
# aliases: list, ls
helm ls

# list the releases that are deployed in all namespaces
helm ls -A

# show the status of the named release in a namespace
helm status my-elasticsearch -n elk

# download the values of the named release
helm get values my-elasticsearch -n elk > values.yaml

# upgrade or install the named release of the chart in a namespace
# and use the values from the values.yaml file
helm upgrade --install my-elasticsearch elastic/elasticsearch -n elk --create-namespace -f values.yaml

# uninstall the named release of the chart in a namespace
# aliases: uninstall, del, delete
helm del my-elasticsearch -n elk

阅读更多

Kubernetes 命令

Kubernetes 命令

常用 pods 命令

# 列出所有不是 Running 状态的 pods
kubectl get pods --all-namespaces --field-selector status.phase!=Running

```sh
# 本地端口转发
kubectl port-forward service/<service-name> 8080:80

阅读更多

数学知识点

三角函数

学用的三角函数值

  0 $\frac{\pi}{6}$ $\frac{\pi}{4}$ $\frac{\pi}{3}$ $\frac{\pi}{2}$
sin 0 $\frac{1}{2}$ $\frac{1}{\sqrt{2}}$ $\frac{\sqrt{3}}{2}$ 1
cos 1 $\frac{\sqrt{3}}{2}$ $\frac{1}{\sqrt{2}}$ $\frac{1}{2}$ 0
tan 0 $\frac{1}{\sqrt{3}}$ 1 $\sqrt{3}$ Undefined

阅读更多

乔布斯2005斯坦福大学演讲

乔布斯演讲原文链接

I am honored to be with you today for your commencementnouskəˈmensmənt, 学位授予典礼;毕业典礼】from one of the finest universities in the world. Truth be told, I never graduated from college, and this is the closest I’ve ever gotten to a college graduation. Today I want to tell you three stories from my life. That’s it. No big deal. Just three stories.

我今天很荣幸能和你们一起参加毕业典礼,斯坦福大学是世界上最好的大学之一。我从来没有从大学中毕业。说实话,今天也许是在我的生命中离大学毕业最近的一天了。今天我想向你们讲述我生活中的三个故事。不是什么大不了的事情,只是三个故事而已。

阅读更多

Linux 系统中文件的 atime, mtime 和 ctime

先上结论:

  • Access time (atime): 最近一次读取文件内容的时间。
  • Modifty time, (mtime): 最近一次修改文件内容的时间。
  • Change time (ctime): 最近一次更改文件元数据的时间
  • 修改文件内容会同时修改 mtimectime,具体原因见下面对 struct stat 的分析。

阅读更多

VSCode Tips

Regex Engine in VSCode

部分内容参考自 Regex in VSCode

VSCode 包含两种搜索方式:

搜索方式 快捷键 正则引擎 作用
Search Ctrl-Shift-F ripgrep 活动侧边栏上的放大镜图标,用于搜索当前工作区中的所有文件夹
Find/Replace Ctrl-F JavaScript 仅适用于当前文档的简单查找/替换工具(可通过单击 编辑->查找 访问)

VSCode 中的工作区搜索由开源的 ripgrep 面向行的搜索工具提供支持。 ripgrep 引擎在底层使用 Rust 正则表达式。如果 ripgrep 引擎无法解析正则表达式,VSCode 会回退到 PCRE2 引擎来处理结果。

比如,ripgrep 不支持反向引用 (backreferences) 和环视 (lookaround),如果搜索中用到这两个功能,VSCode 将自动调用 PCRE2 引擎。

相比之下,编辑器 Find 使用 JavaScript(特别是 ECMAScript 5)正则表达式引擎,该引擎支持反向引用和环视。

阅读更多

理解 sudoers

sudoers 是默认的 sudo 策略插件,它确定用户的 sudo 权限,其策略在 /etc/sudoers 文件或 LDAP 中定义。

sudoers 语法

sudoers options

sudo 的行为可以通过 Default_Entry 行进行修改

  • 输入密码后 30 分钟内不需要再次输入密码
Defaults            timestamp_timeout=30
  • 不再需要用户 peter 输入密码
Defaults:peter      !authenticate

User specifications

User_Sepc

阅读更多

Ansible 笔记

Ansible: What’s the difference between task, role, play and playbook?

Playbookplay 的列表。顶层的 playbook YAML 里只做两件事:

  • 定义 play
  • 使用关键字 import_playbook 从另一个 playbook YAML 文件导入 plays。

playbook 只能被 ansible-playbook 调用。

Task,用手册的话说,就是用来调用一个 ansible 模块。但是,task 不知道它应该运行在哪些主机上。

Play 用来将任务绑定到要运行的服务器上。这里的重点是强制关键字 hosts,它告诉哪些主机受到影响以及如何受到影响。

阅读更多

jq 命令

jq 程序是一个 过滤器:接受输入并产生输出。它有很多内置过滤器用于提取对象的特定字段,将数字转换为字符串或各种其他标准任务。

过滤器可以通过多种方式组合,可以通过管道将一个过滤器的输出传递到另一个过滤器,或者将过滤器的输出收集到一个数组中。

一些过滤器会产生多个结果,例如过滤器会生成其输入数组的所有元素,然后对数组的每个元素运行第二个过滤器。通常,在其他语言中使用循环和迭代完成的事情在 jq 中只是通过管道将过滤器组合在一起来完成。

阅读更多

Openshift

以下命令,如无特别说明,均可以使用 kubectl 替换 oc

kubectl 命令自动补全

参考 kubectl auto completion 设置别名和自动补全。

echo 'source <(kubectl completion zsh)' >>~/.zshrc

echo 'alias k=kubectl' >>~/.zshrc
echo 'complete -o default -F __start_kubectl k' >>~/.zshrc

如果使用 oh-my-zsh,可以直接使用 kubectloc 自动补全插件

阅读更多

Maven 生命周期

生命周期 (Build Lifecycle)

Maven 的核心概念基于 Build Lifecycle。Maven 有三个内建的 build lifecycle

Build Lifecycle Description
default handles project deployment
clean handles project cleaning
site handles the creation of project’s web site

生命周期中的阶段 (Build Phase)

  • Build lifecycle 由多个阶段组成
  • 阶段的执行是有序的,执行某个阶段,会先执行其前面的所有阶段

阅读更多

Jenkins

容器中运行

Master

如果使用 nginx 作为反向代理,并设置 context path 为 /jenkins,需要向容器传入环境变量 --env JENKINS_OPTS="--prefix=/jenkins"

在主机上创建 /var/jenkins_home 目录并修改权限,使得 container 中的 jenkins user 可以访问

mkdir /var/jenkins_home

chown -R 1000:1000 /var/jenkins_home
  • 无证书访问,启动端口为 8080
docker run -it --name jenkins-master -v /var/jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 --restart=on-failure -e JENKINS_OPTS="--prefix=/jenkins" jenkins/jenkins:lts-jdk11

阅读更多

Windows Subsystem Linux (WSL)

安装 Windows 默认发行版

列出可用的发行版

wsl --list --online

# short
wsl -l -o

安装可选的 Linux 发行版

wsl --install -d <distro>

常用操作

关闭 WSL 中的 Linux

wsl --terminate <distro>

# short
wsl -t <distro>

阅读更多

Github API

在 Organization 间迁移 Repositories

Github 提供了 Transfer a repository API, 可以在个人或组织间转移仓库。

在 Github 页面个人头像上选择 Settings -> Developer settings -> Personal access tokens,添加一个新的访问token,作为访问 Github API 的密码。

下面的脚本可用于批量转移多个仓库。

阅读更多

Pandas

在 Jupyterlab 中使用 Pandas

pip install jupyterlab

如果是在 WSL2 系统中使用 Jupyterlab,需要如下配置才能默认使用 Windows 主机上的浏览器打开界面

禁用 use_redirect_file

jupyter lab --generate-config

vim ~/.jupyter/jupyter_lab_config.py
c.ServerApp.use_redirect_file = False

使用环境变量 BROWSER 指定 Windows 主机浏览器路径

export BROWSER="/mnt/c/Program Files/Mozilla Firefox/firefox.exe"

使用 localhost 作为 WSL 系统主机名

vim /etc/wsl.conf
[network]
hostname = localhost

启动 jupyterlab,指定 IP 和端口,否则可能报错

jupyter lab --ip=0.0.0.0 --port 8080

导入 Pandas

import pandas as pd
import numpy as np

print(pd.__version__)
print(np.__version__)

数据结构

pandas-data-structures

阅读更多

Wolfram 使用

安装 Wolfram Engine for Developers

Wolfram Engine for Developers 是 Wolfram Language 的后端核心,安装完成后可以使用 WolframScript 进入命令行执行代码。

安装 WolframLanguageForJupyter 插件

使用 Jupyter notebook 做为 Wolfram Engine 的前端

pip install jupyterlab

git clone https://github.com/WolframResearch/WolframLanguageForJupyter.git

./configure-jupyter.wls add

现在可以在 jupyter lab 中打开 Wolfram Language 的 Notebook。

阅读更多

SELinux 设置

关闭 SELinux

getenforce 命令检查 SELinux 是否已禁用,其结果为 EnforcingPermissiveDisabled 之一,修改 SELinux 配置文件可将其禁用。

sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

如果只想临时关闭 SELinux,可以输入命令

setenforce 0

阅读更多

为 Markdown 添加样式

使用 inline CSS style

在表格中使用颜色

<style>
    .mytable td:nth-child(1) { font-weight: bold; }
    .mytable tr:nth-child(1) td:nth-child(n+2):nth-child(-n+4) { background: red; }
    .mytable tr:nth-child(2) td:nth-child(2) { background: deepskyblue; }
    .mytable tr:nth-child(2) td:nth-child(3) { background: palegreen; }
    .mytable tr:nth-child(2) td:nth-child(4) { background: orange; }
</style>

|       | Column 1 | Column 2 | Column 3 |
| ----- | :------: | :------: | :------: |
| Row 1 |  R1 C1   |  R1 C2   |  R1 C3   |
| Row 2 |  R2 C1   |  R2 C2   |  R2 C3   |
{:.mytable}

阅读更多

macOS Tips

启动台无法切换页面

经常在拖动图标到不同页面的时候发现启动台切换页面失效,会自动切回到第一页,在终端使用下面的命令可以重启控制台

killall Dock

查看系统信息

所有系统信息

osascript -e "system info"

IP 地址

osascript -e "IPv4 address of (system info)"

通过命令行唤醒和睡眠系统

在充电状态下,macbook 睡眠后可以仍可以保持 ssh 链接,可以通过以下命令对 macbook 进行远程操作

阅读更多

重置 Win10 密码

  1. 使用优盘进入 WinPE 系统 (推荐优启通)

  2. 打开命令行程序

     C:
     cd C:\Windows\System32
     move Utilman.exe Utilman.exe.bak
     copy cmd.exe Utilman.exe
    
  3. 拔掉优盘重启系统

  4. 在登录界面点击屏幕右下角的 轻松使用 图标打开命令行工具

     cd C:\Windows\System32
     control userpasswords2
    
  5. 在弹出的对话框中可以重置用户密码。

阅读更多

macOS System Provision

使用恢复系统重新安装 macOS

重新启动 Mac,然后立即按住以下其中一个组合键

  • 安装与电脑兼容的 macOS 最新版本:按住 Option-Command-R
  • 重新安装电脑原始版本的 macOS(包括可用的更新):按住 Shift-Option-Command-R
  • 重新安装储存在电脑内建恢复宗卷中的 macOS 版本:按住 Command-R

阅读更多

Systemctl 命令

systemd-sysv-generator 工具

Unit 命令

列出当前内存中的 units

systemctl list-units

The LOAD column shows the load state, one of loaded, not-found, bad-setting, error, masked. The ACTIVE columns shows the general unit state, one of active, reloading, inactive, failed, activating, deactivating. The SUB column shows the unit-type-specific detailed state of the unit, possible values vary by unit type.

阅读更多

微积分 (Calculus)

微分

切线(tangent line)是数学中的一个基本概念,通常用于函数图形或几何图形,切线的基本定义:

  • 在几何学中,圆的切线被定义为与圆只有一个公共点(切点)的直线。这是切线最直观的定义,可以扩展到其他几何图形,比如椭圆或多边形。
  • 在微积分中,一条切线是曲线在某一特定点上的 直线近似。更严谨地说,若曲线为函数 $y = f(x)$,那么在点 $(a, f(a))$ 处的切线,设为 $y=L(x)$,是该点的唯一一条直线,其斜率(slope)等于函数在该点的导数 $f’(a)$。这条直线 $L(x)$ 与曲线 $f(x)$ 在 $x=a$ 处通过直线的斜率 $m$ 和曲线的导数 $f’(a)$ 联系在一起,换句话说,这条直线在点 $(a, f(a))$ 附近与函数 $y = f(x)$ 的图形非常接近,斜率 $m$ 为
\[m = f'(a) = \lim_{h \to 0} \frac{f(a+h) - f(a)}{h} = \lim_{\Delta x \to 0} \frac{\Delta y}{\Delta x}\]

给定斜率后,可以使用点斜式等式来描述这条直线:

\[y - f(a) = f'(a)(x - a)\]

切线的概念是分析和理解函数局部行为非常有用的工具,它是微积分中研究变化率和做线性近似的基础。

微分

这个线性函数 $L$ 被称为 $f$ 在 $x = a$ 处的 线性化。在上图中, 还有个量被标记了出来, 那就是 $\mathrm{d}f$, 也就是点 $P$ 和 $f(a)$ 的高度之差,可以通过在点 $a$ 处的斜率及 $x$ 的变化量得到

\[\boxed{\mathrm{d}f = f'(a)\Delta x}\]

量 $\mathrm{d}f$ 被称为 $f$ 在 $x=a$ 处的 微分。它是对当 $x$ 从 $a$ 变化为 $a+\Delta x$ 时 $f$ 的变化量的近似。

阅读更多

Cron

Cron 进程

RedHat/CentOS

service crond status

Ubuntu

service cron status

Cron 语法

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command to execute
# 每 30 分钟执行一次 logrotate
*/30 * * * * /usr/sbin/logrotate /etc/logrotate.d/nginx >/dev/null 2>&1

阅读更多

Perl

使用 Perl 手册页快速获得信息

Perl 手册页命令 perldoc。使用 perldoc perl 来获取所有 perldoc 支持的主题。

perldoc perl
perldoc perldoc
perldoc perlcheat

# 查看所有内置函数信息
perldoc perlfunc
# 快速查看某一内置函数信息
perldoc -f chomp

# 查看所有预定义变量信息
perldoc perlvar
# 快速查看某一预定义变量信息
perldoc -v '$_'

阅读更多

PostgreSQL

psql - PostgreSQL 交互式终端

PostgreSQL 交互式终端 psql 的使用,包括连接字符串,免密设置,元命令以及常见的 SQL 语句。

阅读更多

正则表达式比较(Regex - BREs, EREs, PCRE)

常见的几个正则库的语法比较。 原链接: Regex cheatsheet

Regex cheatsheet

Many programs use regular expression to find & replace text. However, they tend to come with their own different flavor.

You can probably expect most modern software and programming languages to be using some variation of the Perl flavor, “PCRE”; however command-line tools (grep, less, …) will often use the POSIX flavor (sometimes with an extended variant, e.g. egrep or sed -r). ViM also comes with its own syntax (a superset of what Vi accepts).

This cheatsheet lists the respective syntax of each flavor, and the software that uses it.

Extended Regular Expression 有时可以通过命令行标志 -E 与 Unix 实用程序一起使用。其他 Unix 实用程序,如 awk,默认使用 ERE

EREBRE 的主要区别在于删除了一些反斜杠:\{...\} 变为 {...} 并且 \(...\) 变为 (...)

阅读更多

Homebrew

Homebrew 中的一些概念及配置国内镜像源方法。

安装 Homebrew

Homebrew国内如何自动安装(国内地址)

执行以下命令,脚本会提示选择国内几个比较常用的镜像,选择中科大镜像然后一路安装即可。

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

# Set Homebrew-bottles mirror
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles

阅读更多

IPv4/IPv6 网络

DNS

  • DoH: DNS over Https
  • DoT: DNS over TLS

公共 DNS 服务

DNS 服务器 IPv4 IPv6 DoH DoT
DNSPod Public DNS 129.29.29.29 2402:4e00:: https://doh.pub/dns-query dot.pub
阿里云 Public DNS 223.5.5.5 2400:3200::1 dns.alidns.com dns.alidns.com
Cloudflare DNS 1.1.1.1      

需要注意,DNS 能否够解析 IPv6 地址和 DNS 本身是否使用 IPv6 地址没有关系。即是说,只要 DNS 支持 IPv6 地址解析,那么访问 IPv4 的 DNS 也可以得到 IPv6 的地址。

阅读更多

使用 Git LFS 存储二进制文件

Git LFS 简介

Git LFS 是由 Atlassian, GitHub 和其他开源贡献者开发的 Git 扩展,目的是减少大文件对 Git 仓库的影响,其以一种偷懒的方式下载相关版本的文件。具体来讲,就是只有在执行 checkout 命令时才会下载文件,而 clonefetch 均不会下载文件。

Git LFS 通过将仓库中的大文件替换为一个 指针文件 来达到这一目的。

阅读更多

设置 Nodejs 环境

Linux 系统下手工安装 Nodejs

从官方下载 Nodejs 安装包

解压安装包到 /usr/local/lib/nodejs

VERSION=v10.16.0
DISTRO=linux-x64
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xvJf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs

阅读更多