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

k8s 使用 OpenEBS 存储

TL;DR

helm repo add openebs https://openebs.github.io/openebs
helm repo update

# 以默认值安装
helm install openebs --namespace openebs openebs/openebs --create-namespace

# 禁用副本存储类型、lvm 本地存储、zfs本地存储,仅保留本地路径存储
helm install openebs --namespace openebs openebs/openebs --set engines.replicated.mayastor.enabled=false --set engines.local.lvm.enabled=false --set engines.local.zfs.enabled=fa
lse --create-namespace
E0311 06:22:00.794754  111105 round_tripper.go:63] CancelRequest not implemented by *kube.RetryingRoundTripper
NAME: openebs
LAST DEPLOYED: Tue Mar 11 06:21:28 2025
NAMESPACE: openebs
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Successfully installed OpenEBS.

Check the status by running: kubectl get pods -n openebs

The default values will install both Local PV and Replicated PV. However,
the Replicated PV will require additional configuration to be fuctional.
The Local PV offers non-replicated local storage using 3 different storage
backends i.e Hostpath, LVM and ZFS, while the Replicated PV provides one replicated highly-available
storage backend i.e Mayastor.

For more information, 
- view the online documentation at https://openebs.io/docs
- connect with an active community on our Kubernetes slack channel.
        - Sign up to Kubernetes slack: https://slack.k8s.io
        - #openebs channel: https://kubernetes.slack.com/messages/openebs

实际使用需充分阅读官方文档。

Local PV Hostpath 用法

定义 StorageClass

以下内容写入 local-hostpath-sc.yaml,默认的 openebs-hostpath 数据存放在主机的 /var/openebs/local 路径下,可以像下面这样自己创建一个。默认使用kubernetes.io/hostname=<node-name> 来标记节点。

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: openebs-local-hostpath
  annotations:
    openebs.io/cas-type: local
    cas.openebs.io/config: |
      - name: StorageType
        value: hostpath
      - name: BasePath
        value: /var/openebs/local
provisioner: openebs.io/local
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer

PersistentVolumes 可以有多种回收策略,包括 “Retain“、”Recycle” 和 “Delete“。 对于动态配置的 PersistentVolumes 来说,默认回收策略为 “Delete"。 这表示当用户删除对应的 PersistentVolumeClaim 时,动态配置的 volume 将被自动删除。 如果 volume 包含重要数据时,这种自动行为可能是不合适的。 那种情况下,更适合使用 “Retain” 策略。 使用 “Retain” 时,如果用户删除 PersistentVolumeClaim,对应的 PersistentVolume 不会被删除。 相反,它将变为 Released 状态,表示所有的数据可以被手动恢复。

pvc 的迁移可以使用 pv-migrateVelero 进行,实现在主机间迁移。

定义 PVC

local-hostpath-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: local-hostpath-pvc
spec:
storageClassName: openebs-hostpath
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5G

Pod 使用

local-hostpath-pod.yaml

apiVersion: v1
kind: Pod
metadata:
name: hello-local-hostpath-pod
spec:
volumes:
- name: local-storage
persistentVolumeClaim:
claimName: local-hostpath-pvc
containers:
- name: hello-container
image: busybox
command:
- sh
- -c
- 'while true; do echo "`date` [`hostname`] Hello from OpenEBS Local PV." >> /mnt/store/greet.txt; sleep $(($RANDOM % 5 + 300)); done'
volumeMounts:
- mountPath: /mnt/store
name: local-storage

清理

kubectl delete pod hello-local-hostpath-pod
kubectl delete pvc local-hostpath-pvc
kubectl delete sc local-hostpath

# 可验证动态创建的 pv 也被删除
kubectl get pv

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

将当前系统做成 docker 镜像

TL; DR

  • Step1: 将当前系统打包

系统进行格式转化并压缩,执行如下命令,生成一个镜像的centos7-base.tar的文件

# 示例打包命令
$ tar --numeric-owner --exclude=/proc --exclude=/sys -zcvpf /data/centos7-svr.tar.gz /

$ tar --numeric-owner \
--exclude=/proc --exclude=/sys \
--exclude=/var/lib/vz \
--exclude=/root \
--exclude=/media \
--exclude=~ \
-zcvpf ~/hci6-ci-base.tar.gz /

$ tar -cvpf /home/buildrpm.tar --directory=/ --exclude=proc --exclude=sys --exclude=dev --exclude=run /
# --numeric-owner:执行所属
# --exclude:排除那些文件或者目录
# -zcvf :打包压缩 p保持文件的绝对路径
  • Step2: 导入镜像并运行

把镜像文件centos7-svr.tar.gz放到装有docker的系统上

docker import centos7-base.tar <docekr-image>
docker run -it --name <contaner-name> <docker-images> /bin/bash

参考文献