Skip to content

Commit

Permalink
auto push
Browse files Browse the repository at this point in the history
  • Loading branch information
go-bai committed Jul 3, 2024
1 parent 87abfdb commit 44381c9
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 28 deletions.
40 changes: 40 additions & 0 deletions content/posts/k8s/controller-runtime.md
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.
125 changes: 125 additions & 0 deletions content/posts/k8s/rke2.md
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)
26 changes: 0 additions & 26 deletions content/posts/kube/controller-runtime.md

This file was deleted.

8 changes: 7 additions & 1 deletion content/posts/linux/shell-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,12 @@ docker save -o all.tar image-a:1.0.0 image-b:1.0.0 image-c:1.0.0
docker load < all.tar
```
## TODO
- 看一下 [the art of command line](https://github.com/jlevy/the-art-of-command-line) 然后融入进这片文档
- 增加 shell 常用的控制循环和条件判断语法
## 参考
- [awk](https://www.ruanyifeng.com/blog/2018/11/awk.html)
- [awk](https://www.ruanyifeng.com/blog/2018/11/awk.html)
- [the art of command line](https://github.com/jlevy/the-art-of-command-line)
2 changes: 1 addition & 1 deletion content/posts/virt/cloudinit.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tags: [cloudinit]

## cloudinit 介绍

> 用于初始化网络, 主机名, 根文件系统, 用户名密码
> 用于在新建的虚拟机中进行时间设置、密码设置、扩展跟文件系统所在分区、设置主机名、运行脚本、安装软件包等初始化设置
## cloudinit iso 镜像制作

Expand Down

0 comments on commit 44381c9

Please sign in to comment.