理解与使用 Container Capabilities
在使用 K8S 过程中,偶尔会遇到如下所示的一段配置: 1securityContext: 2 capabilities: 3 drop: 4 - ALL 5 add: 6 - NET_BIND_SERVICE 实际上这是配置对应的容器的 Capabilities,在我们使用 docker run 的时候可以通过 --cap-add 和 --cap-drop 命令来给容器添加 Linux Capabilities。 ...
在使用 K8S 过程中,偶尔会遇到如下所示的一段配置: 1securityContext: 2 capabilities: 3 drop: 4 - ALL 5 add: 6 - NET_BIND_SERVICE 实际上这是配置对应的容器的 Capabilities,在我们使用 docker run 的时候可以通过 --cap-add 和 --cap-drop 命令来给容器添加 Linux Capabilities。 ...
数据卷(Volume)是 Pod 与外部存储设备进行数据传递的通道,也是 Pod 内部容器间、Pod 与Pod 间、Pod 与外部环境进行数据共享的方式。 Volume 定义了外置存储的细节,并内嵌到 Pod 中作为 Pod 的一部分。其实质是外置存储在Kubernetes 系统的一个资源映射,当负载需要使用外置存储的时候,可以从数据卷(Volume)中查到相关信息并进行存储挂载操作。 ...
1. WaitGroup WaitGroup 等待一组 Goroutine 完成。主 Goroutine 调用 Add(delta) 来设置要等待的 Goroutine 的数量。然后每个 Goroutine 运行并在完成时调用 Done()。同时,可以使用 Wait() 来阻塞,直到所有 Goroutine 完成。 1type WaitGroup struct { 2 noCopy noCopy 3 4 // 64-bit value: high 32 bits are counter, low 32 bits are waiter count. 5 // 64-bit atomic operations require 64-bit alignment, but 32-bit 6 // compilers do not ensure it. So we allocate 12 bytes and then use 7 // the aligned 8 bytes in them as state, and the other 4 as storage 8 // for the sema. 9 state1 [3]uint32 10} wg.Add(delta int):Add 将 delta(可能为负)添加到 WaitGroup 计数器。如果计数器变为 0,所有在 Wait 时阻塞的 Goroutine 将被释放。如果计数器变成负值,Add 会 panic。 wg.Done():当 WaitGroup 同步等待组中的某个 Goroutine 执行完毕后,设置这个 WaitGroup 的 counter 数值减 1,其实就是调用了 Add(-1)。 wg.Wait():表示让当前的 Goroutine 等待,进入阻塞状态。一直到 WaitGroup 的计数器为 0,才能解除阻塞,这个 Goroutine 才能继续执行。 总之,WaitGroup 让某个协程等待其它若干协程都先完成它们各自的任务。 ...
1. 基础特性 1.1 先进后出 对于多个defer语句,类似栈,按先进后出的顺序执行。 1func main() { 2 var whatever [5]struct{} 3 for i := range whatever { 4 defer fmt.Print(i) 5 } 6} 7 8// 43210 1.2 实时解析函数参数 1package main 2 3import "fmt" 4 5func test(a int) {//无返回值函数 6 defer fmt.Println("1、a =", a) //方法 7 defer func(v int) { fmt.Println("2、a =", v)} (a) //有参函数 8 defer func() { fmt.Println("3、a =", a)} () //无参函数 9 a++ 10} 11func main() { 12 test(1) 13} 14 15// 3、a = 2 16// 2、a = 1 17// 1、a = 1 1.3 return 返回机制 defer、return、返回值三者的执行逻辑应该是: ...
Pod 是 K8s 集群中创建和管理的、最小的可部署的计算单元。K8s 不会直接操作容器,而是通过 Pod 封装了容器,集群通过管控 Pod ,便可控制容器的存储、网络等资源,实现资源隔离或共享。 ...
升级 OpenSSH 从选择一个最新的版本 https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/ 1# 获取最新版本 openssh 2wget --no-check-certificate https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.7p1.tar.gz 3 4# 解压 5tar -zxvf openssh-9.7p1.tar.gz 6 7# 安装相关需要组件 8yum -y install pam-devel gcc zlib-devel openssl-devel 9 10# 检查配置 11./configure --prefix=/usr --sysconfdir=/etc/ssh --with-zlib --with-ssl-dir=/usr/local/ssl --with-md5-passwords --mandir=/usr/share/man --with-pam 12 13# 编译安装 14make && make install 编译完成之后会有部分文件中的参数例如 GSSAPIAuthentication 显示不支持,将其删掉即可。 ...
使用golang标准库中的html/template时,在默认情况下渲染模版时为了安全等原因,会将字符串中的部分符号进行转义。 注册自定义转义处理函数 1func unescapeHTML(s string) template.HTML { 2 return template.HTML(s) 3} 在定义转义处理函数后,我们需要使用Funcs()将其注册到模版中。需要注意,注册自定义函数需要在调用Parse()前进行。在注册时我们需要定义一个函数标识符,并在模版文本中使用。在下面例子中我们使用了名为unescapeHTML的函数标识符。 ...
安装 Jaeger Operator 1kubectl create namespace observability 2kubectl create -f https://github.com/jaegertracing/jaeger-operator/releases/download/v1.52.0/jaeger-operator.yaml -n observability 若 rbac-proxy 安装失败,则修改 kube-rbac-prox 镜像地址为 10.101.7.108:80/open_source/kubebuilder/kube-rbac-proxy:v0.13.0 安装 Jaeger 1apiVersion: jaegertracing.io/v1 2kind: Jaeger 3metadata: 4 name: jaeger-prod 5 namespace: observability 6spec: 7 strategy: production 8 storage: 9 type: elasticsearch 10 esIndexCleaner: 11 enabled: true # turn the cron job deployment on and off 12 numberOfDays: 7 # number of days to wait before deleting a record 13 schedule: "55 23 * * *" # cron expression for it to run 14 options: 15 es: 16 server-urls: http://elasticsearch.szhems.svc:9200 17 index-prefix: dev 18 # tls: 19 # ca: /es/certificates/ca.crt 20 # secretName: jaeger-secret 21 # volumeMounts: 22 # - name: certificates 23 # mountPath: /es/certificates/ 24 # readOnly: true 25 # volumes: 26 # - name: certificates 27 # secret: 28 # secretName: quickstart-es-http-certs-public go-zero 每个服务的配置文件下添加Telemetry配置 1Log: 2 ServiceName: platform-api 3 Level: info 4 Stat: false 5 TimeFormat: 2006-01-02 15:04:05 参考资料: ...
使用精简的基础镜像 Alpine Alpine一个基于 musl libc 和 busybox、面向安全的轻量级 Linux 发行版,压缩体积只有 3M 左右,很多流行的镜像都有基于 alpine 的制作的基础镜像。 scratch scratch 是一个空镜像,如果我们的应用是一个不依赖动态链接库的、包含所有依赖的二进制文件,则可以使用 scratch 作为基础镜像,此时镜像的体积差不多就是二进制文件的体积。 ...
波特率 Baud Rate 波特率是发送数据位的速度。 PLC 设备中使用的波特率的常见值包括:1200、9600、19200、38400。 数据位 Data Bits 数据位是每帧中数据的位数。 PLC 设备使用的常见值包括 7 或 8 个数据位。 ...