分类目录归档:技术笔记

k8s csi-driver-nfs的一个坑

TL;DR

发现 k8s csi 组的社区项目 csi-driver-nfs v4.10v4.11 至少这两个版本存在删除 pv 时会连带将整个根删除的问题。

声明 StorageClass 时虽然支持 subDir ,类似这样:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-aliyun-gz
provisioner: nfs.csi.k8s.io
parameters:
  share: "/csi"
  server: "28364f4a1fa-eok75.cn-guangzhou.nas.aliyuncs.com"
  #server: "172.26.12.20"
  #subDir: "${pvc.metadata.namespace}/${pvc.metadata.name}"
reclaimPolicy: Delete
#volumeBindingMode: WaitForFirstConsumer
volumeBindingMode: Immediate
allowVolumeExpansion: true
mountOptions:
#  - nolock,tcp,noresvport
  - vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport

但如果类似这样使用 subDir 声明路径,同命名空间下的其他 pvc 删除,会导致整个 subDir 根目录都被删除。目前官方 pr 已经修复,但实测还是有问题,有空再研究一下代码,不知道是不是刻意为之。

回溯 issuer 历史发现是有人提了 bug 发现目录下出现很多空目录,认为需要删除,修复者修复这一问题时错误的将整个根删除。为了规避这一问题,暂时回退到更早的 4.9 版本 csi

helm upgrade --install csi-driver-nfs csi-driver-nfs/csi-driver-nfs --namespace kube-system --version v4.  
9.0 -f values.yaml

升级版本要谨慎,新装版本要充分测试,特别是这种涉及数据安全的!

最后发现 sig 组还有一个 nfs-subdir-external-provisioner 可以看一下。

References

k3s 容器 mirror 配置方法

TL; DR

root@tencent-sh1:~# cat /etc/rancher/k3s/registries.yaml 
mirrors:
  "docker.io":
    endpoint:
      - "https://harbor.xxx.me"
    rewrite:
      "^(.*)": "mirror-dockerhub/$1"
  "registry.k8s.io":
    endpoint:
      - "https://harbor.xxx.me"
    rewrite:
      "^(.*)": "mirror-registry-k8s-io/$1"
  "ghcr.io":
    endpoint:
      - "https://harbor.xxx.me"
    rewrite:
      "^(.*)": "mirror-registry-ghcr-io/$1"
  "quay.io":
    endpoint:
      - "https://harbor.xxx.me"
    rewrite:
      "^(.*)": "mirror-registry-quay-io/$1"

以上是我的配置,在 harbor 中镜像以上镜像源,之后这样 配置即可。

如果没有路径,比如使用 registry 镜像,忽略 rewrite 部分即可。

References

wordpress 使用 k8s 部署并使用 nginx ingress 代理无限 302 到 ssl 问题解决

发现容器化之后,wp 网站打开一直尝试 302 到 https 的页面,即使我当前已经是 https 了,经过排查是由于代理提供了 ssl 但 wordpress 不知道,默认会再重定向一次,出现无限 302 。

TL; DR

解决方法很简单,只需在 wp 配置文件 /wp-config.php 中增加这几行即可解决:

define( 'FORCE_SSL_ADMIN', true );
// in some setups HTTP_X_FORWARDED_PROTO might contain 
// a comma-separated list e.g. http,https
// so check for https existence
if( strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false )
    $_SERVER['HTTPS'] = 'on';

方法来源于官网.

References

ArchLinux pacman 一键找到最快的镜像源清单

curl -s "https://archlinux.org/mirrorlist/?country=CN&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 -

运行这个命令,即可自动从 archlinux 官方 mirror 清单获取中国 (CN) 的镜像清单,并调用 rankmirrors 测速得到速度最快的前5个。

配置到 /etc/pacman.d/mirrorlist 目录中即可使用。

References

LLM 聚合 API 价格对比

List

  • gpt-4
  • gpt-4o
  • claude-3-7-sonnet-20250219
  • `claude-3-7-sonn

单位:Inout/Output /M

Model gpt-4o gpt-4o-mini deepseek-r1 deepseek-v3 claude-3-7-sonnet claude-3-5-sonnet
UniAPI $0.2871/$1.1484 $2.376/$11.88 $2.376/$11.88
GPTAPI ¥0.07/¥0.14 ¥5.25/¥26.25 ¥5.25/¥26.25
OpenRouter $5/$7 $3/$15 $3/$15
AiHubMix $0.62/$2.48 $3.3/$16.5
V3 API $1.8/$7.2 $7.4/$37

Refereneces

k8s 使用 pv-migrate 迁移 pvc

TL;DR

安装

wget https://github.com/utkuozdemir/pv-migrate/releases/download/v1.7.1/pv-migrate_v1.7.1_linux_x86_64.tar.gz
tar -xvf pv-migrate_v1.7.1_linux_x86_64.tar.gz
mv pv-migrate /usr/local/bin

用法

pv-migrate migrate \
  --source-namespace default \
  --dest-namespace default \
  localpv-vol csi-lvmpv

🚀 Starting migration
💭 Will attempt 3 strategies: mnt2, svc, lbsvc
🚁 Attempting strategy: mnt2
📂 Copying data... 100% |██████████████████████████████| (3.4 GB/s)     
📂 Copying data...   0% |                              |  [0s:0s]🧹 Cleaning up
📂 Copying data... 100% |██████████████████████████████|         
✨ Cleanup done
✅ Migration succeeded

References

k3s 部署 kube-prometheus-stack 监控栈

TL;DR

$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
$ helm repo update
$ helm show values prometheus-community/kube-prometheus-stack
$ helm show values prometheus-community/kube-prometheus-stack > values.yaml
# Edit values.yaml
$ helm install prometheus-community prometheus-community/kube-prometheus-stack  --namespace monitoring -f values.yaml --create-namespace
# update values.yaml
$ helm upgrade --install prometheus-community prometheus-community/kube-prometheus-stack  --namespace monitoring -f values.yaml

References

helm operation 中断锁死问题解决

两种方案:

解决办法

方法一,卸载重装

helm uninstall <release name> -n <namespace>

方法二,回滚

This error can happen for few reasons, but it most commonly occurs when there is an interruption during the upgrade/install process as you already mentioned.
发生此错误的原因有很多,但最常见的原因是升级/安装过程中出现中断,正如您之前提到的。

To fix this one may need to, first rollback to another version, then reinstall or helm upgrade again.
要修复这个问题,可能需要先回滚到另一个版本,然后重新安装或再次进行 helm upgrade。

Try below command to list
尝试以下命令列出

helm ls --namespace 
<namespace>

but you may note that when running that command ,it may not show any columns with information
但你可能会注意到,运行该命令时,它可能不会显示任何包含信息的列

Try to check the history of the previous deployment
尝试检查上次部署的历史记录

helm history 
<release> --namespace <namespace>

This provides with information mostly like the original installation was never completed successfully and is pending state something like STATUS: pending-upgrade state.
这提供的信息大多类似于原始安装从未成功完成并且处于待处理状态,例如状态:待处理升级状态。

To escape from this state, use the rollback command:
要退出此状态,请使用 rollback 命令:

helm rollback 
<release> <revision> --namespace <namespace>

revision is optional, but you should try to provide it.
修订是可选的,但您应该尝试提供它。

You may then try to issue your original command again to upgrade or reinstall.
然后您可以尝试再次发出原始命令来升级或重新安装。

References