Hi there 👋

Welcome to my blog

K3s traefik expose k8s dashboard

安装dashboard 参考https://docs.k3s.io/installation/kube-dashboard。如果获取k8s dashboard yaml出现问题,可能是这个版本本身还不存在,可直接看k8s官网使用的是哪个版本的dashboard yaml。k3s kubectl -n kubernetes-dashboard create token admin-user生成的token在登录时需要用到 准备证书 部署完毕后,生成证书,这里生成了泛域名证书,方便使用 1 2 3 openssl req -newkey rsa:2048 -nodes -keyout root.key -x509 -days 365 -out root.crt -subj "/CN=Root CA" openssl req -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr -subj "/CN=home.site" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:home.site,DNS:*.home.site")) openssl x509 -req -in domain.csr -CA root.crt -CAkey root.key -CAcreateserial -out domain.crt -days 365 -extensions SAN -extfile <(cat /etc/ssl/openssl....

July 10, 2023 · 1 min · 138 words · Me

Rust_async_await

Rust Async Await 协程并不是抢占式任务模型,所以不是在任意时间点强制暂停正在运行的任务,而是让每个任务一直运行,直到它自愿放弃对cpu的控制,这样任务可以在合适时间点暂停。那么有三个问题, 1. 在rust中异步代码是怎么执行的? 2. 切换不同的任务时,被切换的任务的状态信息怎么保存? 3. 任务什么时候再次被执行? 1. 在rust中异步代码是怎么执行的? 在rust中写异步代码时就像写同步代码一样,但是rust为了实现这一机制,会将async code block 编译为一个状态机,使用下面这个例子来说明。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 usestd::future::Future;usestd::pin::Pin;usestd::task::{Context,Poll};usestd::time::{Duration,Instant};struct Delay{when: Instant,}implFutureforDelay{type Output=&'staticstr;fn poll(self: Pin<&mutSelf>,cx: &mutContext<'_>)-> Poll<&'staticstr>{ifInstant::now()>=self.when{println!("Hello world");Poll::Ready("done")}else{// Ignore this line for now. cx.waker().wake_by_ref();Poll::Pending}}}asyncfn sleep_some_millis(){letarray=[1,2,3];letnum=&array[2];letwhen=Instant::now()+Duration::from_millis(num);letfuture=Delay{when};letout=future.await;assert_eq!(out,"done");} 以上是正常编写的异步代码,但是在编译器编译后,会生成类似下面的代码...

June 26, 2023 · 1 min · 174 words · Me

Tokio源码阅读2

main thread execution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #[track_caller]pubfn block_on<F: Future>(&self,future: F)-> F::Output{#[cfg(all(tokio_unstable, feature = "tracing"))]letfuture=crate::util::trace::task(future,"block_on",None,crate::runtime::task::Id::next().as_u64(),);let_enter=self.enter();match&self.scheduler{Scheduler::CurrentThread(exec)=>exec.block_on(&self.handle.inner,future),#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]Scheduler::MultiThread(exec)=>exec.block_on(&self.handle.inner,future),}} 执行multithread::block_on 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /// Blocks the current thread waiting for the future to complete. /// /// The future will execute on the current thread, but all spawned tasks /// will be executed on the thread pool....

June 12, 2023 · 4 min · 826 words · Me

tokio源码阅读1

tokio runtime 基本组件 这个系列文章会以这段代码为样例,了解tokio内部运行机制 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 usestd::error::Error;usetokio::io::{AsyncReadExt,AsyncWriteExt};usetokio::net::TcpListener;usetokio;fn main()-> Result<(),Box<dynError>>{letrt=tokio::runtime::Runtime::new().unwrap();rt.block_on(async{//tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; letlistener=tokio::net::TcpListener::bind("127.0.0.1:8080").await.unwrap();loop{let(mutsocket,_)=listener.accept().await.unwrap();tokio::spawn(asyncmove{letmutbuf=vec![0;1024];// In a loop, read data from the socket and write the data back. loop{letn=socket.read(&mutbuf).await.expect("failed to read data from socket");ifn==0{return;}socket.write_all(&buf[0..n]).await.expect("failed to write data to socket");println!...

June 12, 2023 · 4 min · 734 words · Me

python描述器(1)

先看一段代码,这段代码来自《流畅的python》 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 class Quantity: def __init__(self, storage_name): self.storage_name =storage_name def __set__(self, instance, value): if value > 0: # setattr(instance, self.storage_name, value) instance.__dict__[self.storage_name] = value else: raise ValueError('value must be > 0') def __get__(self, instance, owner): return getattr(instance, self.storage_name) class LineItem: weight1 = Quantity('weight') price1 = Quantity('price') def __init__(self, description, weight, price): self....

April 6, 2020 · 1 min · 148 words · Me