k8s-debug

kubernetes集群部署 Debug 官方文档中有Troubleshooting这个主题,包含以下内容: Debug Pods Debug Services Debug a StatefulSet Debug Init Containers Debug Running Pods Determine the Reason for Pod Failure Get a Shell to a Running Container 里面有常见问题的排查方法介绍 常见套路 1. 使用 busybox 方法一:kubectl run curl --image=radial/busyboxplus:curl -i --tty 方法二:kubectl debug targetPod -it --image=busybox 2. 使用 initContainer 给Pod、Deployment增加 initContainer,在其中添加debug操作。 推荐阅读文档: 链接 查看 initContainer 日志: kubectl logs pod_name -c initContainerName 3....

created: 2022-03-02  |  updated: 2022-03-02  |  阿秀

k8s快速入门

1. 概念入门 master节点 worker节点 Pod Kubernetes最小管理单位,一个节点可以拥有多个Pod,一个Pod可以拥有多个容器 2. 安装 2.1 minikube 安装教程: https://minikube.sigs.k8s.io/docs/start/ 2.2 腾讯云集群 按步骤很容易起一个Kubernetes集群 3. 常用命令 1 2 3 4 5 6 7 8 9 10 11 12 kubectl apply -f app.yaml # 部署应用 kubectl get deployment # 查看 deployment kubectl get pod -o wide # 查看 pod kubectl describe pod pod-name # 查看 pod 详情 kubectl logs pod-name # 查看 log kubectl exec -it pod-name -- bash # 进入 Pod 容器终端, -c container-name 可以指定进入哪个容器。 kubectl scale deployment test-k8s --replicas=5 # 伸缩扩展副本 kubectl port-forward pod-name 8090:8080 # 把集群内端口映射到节点 kubectl rollout history deployment test-k8s # 查看历史 kubectl rollout undo deployment test-k8s # 回到上个版本 kubectl rollout undo deployment test-k8s --to-revision=2 # 回到指定版本 kubectl delete deployment test-k8s # 删除部署 4....

created: 2022-02-10  |  updated: 2022-02-10  |  阿秀

Go map

前言 go版本: go version go1.17.3 linux/amd64 建议阅读注释 如果没有实现过朴素的哈希表,推荐写一下leetcode 706.设计哈希映射,连最简单的哈希表都没写过就想来看实际工程实践中经过大量性能考量、折衷和优化的哈希表,还是比较困难的。 map总览 map相关的结构体定义在 runtime/map.go中: 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 // A header for a Go map. type hmap struct { count int // 表示map中的键值对个数,等于len()操作返回值 flags uint8 B uint8 // B=log_2(len(buckets)) noverflow uint16 // overflow buckets 的数量的近似值 hash0 uint32 // 哈希种子,为哈希函数的结果增加随机性 buckets unsafe....

created: 2021-12-18  |  updated: 2021-12-19  |  阿秀

Go slice、扩容机制、常见用法

Slice详解 基础用法 slice定义,在runtime/slice.go中 1 2 3 4 5 type slice struct { array unsafe.Pointer len int cap int } slice拥有指针、长度、容量这几个字段,其底层是一个数组,用指针array指代 切片操作切片名[startIndex:endIndex:maxIndex],其操作的区间是[startIndex, endIndex),是左闭右开的,最多取到下标maxIndex-1处,endIndex<=maxIndex 注意与python区分: python的切片第二个冒号后是步长step, 不支持像python切片那样的支持逆置slice[::-1]以及slice[-1],逆置只能手动写for循环;访问最后一个元素只能slice[len(slice)-1] slice的5种创建方式: 1 2 3 4 5 6 var slice1 []int // nil slice slice2 := []int{1, 2, 3} slice3 := make([]int, 1, 2) // 长度为1,容量为2,长度必须小于等于容量 slice4 := *new([]int) // nil slice,注意取值运算* slice5 := slice2[1:2] slice6 := []struct{x, y int}{{-1, 0}, {1, 0}, {0, -1}, {0, 1}} 注意事项...

created: 2021-12-18  |  updated: 2021-12-19  |  阿秀

Go testing(test && benchmark)

引言 Go提供了testing包用来进行单元测试和基准测试(benchmark),使用go test指令运行对应目录下的测试用例,并输出测试结果。 单元测试 一个例子引入,文件名为some_func_test.go: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 package main import "testing" func Echo(str string) string { return str } func TestEcho(t *testing.T){ str := "来♂" if Echo(str) != str { t.Errorf("Echo fail\n") } } 在some_func_test.go文件的父级目录下打开shell,执行go test,则会运行测试用例TestEcho() 测试文件的命名格式为xxx_test.go, 如本例子为some_func_test.go 测试用例命名规则为TestXXX, 如例子中的TestEcho(t *testing.T) 测试需要用到的包是testing testing.T用于普通测试用例 testing.M用于TestMain测试用例 testing.B用于基准测试(benchmark) go test其他参数 go test -v 会显示每个测试用例的结果 go test -cover 会显示覆盖率 go test -run TestAdd 用-run指定运行的测试用例, 支持正则表达式 子测试集 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 package main import ( "fmt" "testing" ) func TestWalk(t *testing....

created: 2021-12-18  |  updated: 2021-12-19  |  阿秀

Go 文件操作

os.File 在Go中,文件被抽象为File结构体 1 2 3 4 5 6 7 8 9 10 11 12 type File struct { *file // os specific } type file struct { pfd poll.FD name string dirinfo *dirInfo // nil unless directory being read nonblock bool // whether we set nonblocking mode stdoutOrErr bool // whether this is stdout or stderr appendMode bool // whether file is opened for appending } File是操作系统相关的,在linux下,File支持的方法在os/file_posix....

created: 2021-12-18  |  updated: 2021-12-19  |  阿秀

Go-channel详解以及Channel用例大全

Channel基础 核心哲学 Do not communicate by sharing memory; instead, share memory by communicating. “不要通过共享内存的方式进行通信,而是应该通过通信的方式共享内存”,channel便是这一理念的支持和体现 基本操作 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 var ch chan int // 零值通道,此外,通道的零值是为nil ch1 := make(chan int) // 创建非缓冲通道 close(ch1) // 关闭通道 ch2 := make(chan struct{}) // struct{}类型的通道 ch3 := make(chan int, 1) // 创建容量为1的缓冲通道 ch3 <- 1 // 往通道中写1 data, ok := <- ch2 // 从通道中读取, 根据ok可知是否成功获取值,ok可省 len(ch2) // 通道当前长度 cap(ch2) // 通道容量 for { // 使用select进行多通道操作 select { case <-ch2: // 接收操作 fmt....

created: 2021-12-18  |  updated: 2021-12-19  |  阿秀

python包管理工具poetry

前言 poetry是一个python包管理工具,类似于pipenv,内部依赖virtualenv。用PEP518中提出的pyproject.toml文件来记录项目依赖,以替代setup.py, requirements.txt, setup.cfg, MANIFEST.in poetry是一个新的产物,吸收了部分“前辈”的优点,并解决了部分它们的缺点,目前(21年6月8日)github上star为15k,值得注意 使用体验 遇到过lock非常久的情况 安装 1 pip install poetry 更新poetry 1 poetry self update 在update后添加版本号可以更新到指定版本;使用--preview选项可以更新到预览版本 生成新的项目脚手架 1 poetry new project_name 会有一系列的命令行交互,用来生成项目 在已有的项目上生成 1 poetry init 生成指定python版本的虚拟环境 1 poetry env use python3.7 删除虚拟环境 1 poetry env remove python3.7 查看当前虚拟环境信息 1 poetry env info 列出系统中存在的虚拟环境 1 poetry env list 激活虚拟环境 1 poetry shell 安装pyproject....

created: 2021-06-08  |  updated: 2021-11-25  |  阿秀