-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
173 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: "Controller Runtime" | ||
date: 2024-06-01T10:42:13+08:00 | ||
draft: false | ||
toc: true | ||
tags: [informer,controller,workqueue] | ||
--- | ||
|
||
> [controller-runtime](https://github.com/kubernetes-sigs/controller-runtime)是在[client-go/tools/cache](https://github.com/kubernetes/client-go/tree/master/tools/cache)和[client-go/util/workqueue](https://github.com/kubernetes/client-go/tree/master/util/workqueue)的基础上实现的, 了解`client-go/tools/cache`和`client-go/util/workqueue`对理解`controller-runtime`很有帮助 | ||
## 介绍informer | ||
|
||
带着问题看 | ||
|
||
## 开发CRD时想到的一些问题 | ||
|
||
### 更新local store缓存和触发reconcile是否有先后顺序 | ||
|
||
### 同一个crd object会不会同时被reconcile | ||
|
||
这个全靠Queue数据结构设计的精妙, 保证了正在执行的reconcile不会处理相同的object | ||
|
||
向queue中增加object之前会检查是否有次object存在于queue中,如果不存在则加入dirty set,如果也不存在于processing set才会加入queue中,当processing中的处理完成之后(调用Done),会将object从processing set种移除,如果次object在处理过程中加入到了dirty set,则将object再次加入到queue中 | ||
https://www.cnblogs.com/daniel-hutao/p/18010835/k8s_clientgo_workqueue | ||
|
||
有几种队列,Queue,DelayingQueue,RateLimitingQueue | ||
|
||
### 如何解决进入reconcile之后读到的是旧数据的问题 | ||
|
||
读到旧数据是否说明是先出发reconcile再更新local store的 | ||
|
||
My cache might be stale if I read from a cache! How should I deal with that? | ||
|
||
在更新或patch status之后,通过wait.Pool(100ms, 2s, func()(bool, error))校验cache中的本object数据直至更新 | ||
|
||
https://github.com/kubernetes-sigs/controller-runtime/blob/main/FAQ.md#q-my-cache-might-be-stale-if-i-read-from-a-cache-how-should-i-deal-with-that | ||
|
||
https://github.com/kubernetes/test-infra/blob/8f0f19a905a20ed6f76386e5e11343d4bc2446a7/prow/plank/reconciler.go#L516-L520 | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
--- | ||
title: "RKE2" | ||
date: 2024-07-01T21:24:49+08:00 | ||
draft: false | ||
toc: true | ||
tags: [k8s,rke2] | ||
--- | ||
|
||
> 通过RKE2快速搭建测试使用的k8s集群环境 | ||
## 环境准备 | ||
|
||
1. 准备bridge网络br0 | ||
2. 准备ubuntu 22.04 server qcow2镜像 | ||
3. 准备libvirt环境 | ||
|
||
## 创建虚拟机 | ||
|
||
### 准备 cloudinit 镜像 | ||
|
||
```bash | ||
cat <<EOFALL > gen-cloudinit-iso.sh | ||
#!/bin/bash | ||
set -eux | ||
CLOUD_INIT_DIR="/var/lib/libvirt/disks/\${VM}/cloudinit" | ||
FILENAME="\${CLOUD_INIT_DIR}/init.iso" | ||
mkdir -p \${CLOUD_INIT_DIR} | ||
cat <<EOF > \${CLOUD_INIT_DIR}/meta-data | ||
instance-id: \${VM} | ||
local-hostname: \${VM} | ||
EOF | ||
# 更多配置参照 https://cloudinit.readthedocs.io/en/latest/explanation/format.html | ||
cat <<EOF > \${CLOUD_INIT_DIR}/user-data | ||
#cloud-config | ||
EOF | ||
# 参考 kubevirt /pkg/cloud-init/cloud-init.go:defaultIsoFunc | ||
xorrisofs -output \$FILENAME -volid cidata -joliet -rock -partition_cyl_align on \${CLOUD_INIT_DIR}/user-data \${CLOUD_INIT_DIR}/meta-data | ||
EOFALL | ||
|
||
VM=k8s-node01 bash gen-cloudinit-iso.sh | ||
``` | ||
|
||
### 准备系统盘并创建虚拟机 | ||
|
||
```bash | ||
VM=k8s-node01 | ||
mkdir -p /var/lib/libvirt/disks/${VM} | ||
qemu-img create -f qcow2 -F qcow2 -b /var/lib/libvirt/images/ubuntu.qcow2 /var/lib/libvirt/disks/${VM}/sysdisk.qcow2 200G | ||
qemu-img create -f qcow2 /var/lib/libvirt/disks/${VM}/datadisk01.qcow2 500G | ||
qemu-img create -f qcow2 /var/lib/libvirt/disks/${VM}/datadisk02.qcow2 500G | ||
qemu-img create -f qcow2 /var/lib/libvirt/disks/${VM}/datadisk03.qcow2 500G | ||
|
||
virt-install \ | ||
--name ${VM} \ | ||
--memory 16384 \ | ||
--vcpus 8 \ | ||
--disk /var/lib/libvirt/disks/${VM}/sysdisk.qcow2,device=disk,bus=scsi \ | ||
--disk /var/lib/libvirt/disks/${VM}/datadisk01.qcow2,device=disk,bus=scsi \ | ||
--disk /var/lib/libvirt/disks/${VM}/datadisk02.qcow2,device=disk,bus=scsi \ | ||
--disk /var/lib/libvirt/disks/${VM}/datadisk03.qcow2,device=disk,bus=scsi \ | ||
--disk /var/lib/libvirt/disks/${VM}/cloudinit/init.iso,device=cdrom,bus=scsi \ | ||
--network bridge=br0 \ | ||
--import \ | ||
--os-variant ubuntu22.10 \ | ||
--noautoconsole | ||
``` | ||
|
||
## 安装 RKE2 | ||
|
||
### 脚本在线安装 | ||
|
||
```bash | ||
# TODO 指定 cni | ||
curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn sh - | ||
systemctl enable rke2-server.service | ||
systemctl start rke2-server.service | ||
``` | ||
|
||
### 离线安装 | ||
|
||
TODO | ||
|
||
### 配置 | ||
|
||
```bash | ||
# kubectl ctr crictl... | ||
CONFIG="PATH=\$PATH:/var/lib/rancher/rke2/bin/" | ||
grep "$CONFIG" ~/.bashrc || echo "$CONFIG" >> ~/.bashrc && source ~/.bashrc | ||
|
||
# command auto completiom | ||
CONFIG="source <(kubectl completion bash)" | ||
grep "$CONFIG" ~/.bashrc || echo "$CONFIG" >> ~/.bashrc && source ~/.bashrc | ||
|
||
# KUBECONFIG ENV | ||
CONFIG="export KUBECONFIG=/etc/rancher/rke2/rke2.yaml" | ||
grep "$CONFIG" ~/.bashrc || echo "$CONFIG" >> ~/.bashrc && source ~/.bashrc | ||
|
||
# CRI_CONFIG_FILE | ||
CONFIG="export CRI_CONFIG_FILE=/var/lib/rancher/rke2/agent/etc/crictl.yaml" | ||
grep "$CONFIG" ~/.bashrc || echo "$CONFIG" >> ~/.bashrc && source ~/.bashrc | ||
|
||
# install helm | ||
HELM_LATEST_VERSION=v3.15.2 | ||
wget https://get.helm.sh/helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz | ||
tar -zxvf helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz | ||
mv linux-amd64/helm /usr/local/bin/helm | ||
rm -f helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz && rm -rf linux-amd64/ | ||
``` | ||
|
||
## 安装 rook ceph | ||
|
||
https://rook.io/docs/rook/latest-release/Getting-Started/quickstart/ | ||
|
||
## 安装 kube-prometheus-stack | ||
|
||
## 参考 | ||
|
||
- [[RKE2 docs] quickstart](https://docs.rke2.io/zh/install/quickstart) | ||
- [[RKE2 docs] CLI 工具](https://docs.rke2.io/zh/reference/cli_tools) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters