《kubebuilder 从零开始实战》 - 04. 使用注解完整字段值约束

使用注解完整字段值约束 代码在: https://github.com/tangx/kubebuilder-zero-to-one 在 /api/v1/redis_types.go 中,使用注解完成字段值约束。 约束条件必须以 //+kubebuilder:validation:<METHOD>:=<VALUE> 为格式, 符号之间 没有空格。 约束条件必须 紧邻 字段, 且在字段上方。 https://book.kubebuilder.io/reference/markers/crd-validation.html 1 2 3 4 5 6 7 8 9 10 type RedisSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file Replicas int `json:"replicas,omitempty"` //+kubebuilder:validation:Minimum:=1234 //+kubebuilder:validation:Maximum:=54321 Port int32 `json:"port,omitempty"` } 重新编译安装 1 make install 使用命令查看查看 1 2 3 4 5 6 7……

阅读全文

《kubebuilder 从零开始实战》 - 03. 优化配置 发布 crd controller 到集群

优化配置 发布 crd controller 到集群 设置 docker server 网络代理, 避免编译的时候下载所依赖的 gcr.io 镜像失败。 参考文章 设置 docker server 网路代理 修改 Makefile, 设置默认 image name 1 2 3 4 VERSION ?= v$(shell cat .version) # Image URL to use all building/pushing image targets IMG ?= cr.docker.tangx.in/jtredis/controller:$(VERSION) 修改镜像 pull 策略。 在 /config/manager/manager.yaml 配置文件中, 添加 imagePullPolicy 策略。 由于本地开发, 并不准备上传到云上, 所以设置为 IfNotPresent。 1 2……

阅读全文

《kubebuilder 从零开始实战》 - 02. 定义对象 CRD 字段, 实现第一个 DEMO

定义对象 CRD 字段, 实现第一个 DEMO 代码在: https://github.com/tangx/kubebuilder-zero-to-one 定义 CRD Redis 对象字段 在 /api/v1/redis_types.go 中, 增加 Replicas 和 Port 字段。 1 2 3 4 5 6 7 8 9 type RedisSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file // Foo is an example field of Redis. Edit redis_types.go to remove/update // Foo string `json:"foo,omitempty"` Replicas int `json:"replicas,omitempty"` Port int32 `json:"port,omitempty"` } 这个 RedisSpec 对应 /deploy/my-op-redis.yml 中的 spec 1 2 3 4 5 6 7 8 9 10 apiVersion: myapp.tangx.in/v1 kind: Redis metadata: name: my-op-redis spec: replicas: 1 port: 3333 编码 Reconcile 调谐逻辑 在 /controllers/redis_controller.go 中编码 R……

阅读全文

《kubebuilder 从零开始实战》 - 01. 使用 kuberbuilder 初始化项目

使用 kuberbuilder 初始化项目 代码在: https://github.com/tangx/kubebuilder-zero-to-one 1 2 kubebuilder init --domain tangx.in kubebuilder create api --group myapp --version v1 --kind Redis 1 2 3 4 5 6 7 8 9 apiVersion: myapp.tangx.in/v1 kind: Redis metadata: name: my-op-redis spec: replicas: 1 port: 3333 1 2 3 4 5 # 安装 make install # 卸载 make uninstall 查看 crd 1 2 3 k get crd |grep tangx.in redis.myapp.tangx.in 2021-11-19T06:16:43Z……

阅读全文

Golang 库: 为什么 Golang slog 库不支持 Fatal 了

Golang 库: 为什么 Golang slog 库不支持 slog.Fatal API 原文链接: https://tangx.in/posts/2023/01/06/why-dont-golang-slog-support-fatal-api/ 使用 slog 默认不支持 Fatal 如果直接把 slog 当成 log 使用, 会有一点点头疼 1 2 3 4 5 6 7 8 9 10 11 func main() { slog.Debug("debug") slog.Info("info") slog.Warn("warn") slog.Error("err", fmt.Errorf("game over")) // slog.Fatal("don't support") } // 2023/01/06 07:41:50 INFO info // 2023/01/06 07:41:50 WARN warn // 2023/01/06 07:41:50 ERROR err err="game over" slog 默认日志级别 是 info, 无法输出 DEBUG 日志。 需要自定义 handler 实现日志级别判断。 参考 Golang 库: 怎么使用 golang slog 设置日志……

阅读全文

Golang 库: 怎么使用 golang slog 设置日志 Debug 等级

Golang 库: 怎么使用 golang slog 设置日志 Debug 等级 原文链接: https://tangx.in/posts/2023/01/06/how-to-set-debug-level-in-golang-slog/ 在 golang 中, 日志统一 一直都是一个头疼的问题。 在 exp 中, Go 加入了一个 新库 exp/slog , 希望能转正。 这里有一些关于 slog 的介绍, 可以参考 Go 十年了,终于想起要统一 log 库了! 使用 slog 习惯误区, 默认日志级别是 Info 如果直接把 slog 当成 log 使用, 可能又一点问题。 1 2 3 4 5 6 7 8 9 10……

阅读全文

腾讯企业邮箱收到不 Gmail 邮件, DNS 记录 CNAME 记录与 MX 记录冲突

腾讯企业邮箱收到不 Gmail 邮件, DNS 记录 CNAME 记录与 MX 记录冲突 原文链接: https://tangx.in/posts/2023/01/06/dns-record-cname-confilic-with-mx/ 为了统一, 我申请了腾讯企业邮箱, 绑定了本站的域名。 但是在测试邮件的时候, 却发现 企业邮箱 发送邮件 一切正常 可以收到来自国内邮箱的邮件, 例如 QQ, 163, 却 收不到 来自 Gmail 的邮件。 查询资料后, 确定是在 DNS 解析记录中, CNAME 与 MX 记录冲突。 由……

阅读全文

从零开始写 k8s 发布工具 - 4.1. 使用 cobrautils 为命令添加更实用的命令参数

4.1. 使用 cobrautils 为命令添加更实用的命令参数 之前的章节, 我们陆陆续续给 kustz 库添加了很多丰富服务的配置 但 kustz 命令, 还是处于一个很原始的命令状态。 接下来我们给 kustz 添加一些更丰富的参数 , 使 kustz 用起来更顺手。 在 CICD 的中, 一般情况下 变量,健康检查, 镜像策略 等很难发生变动。 而镜像名称 经常性 的在每次打包后发生变化……

阅读全文

从零开始写 k8s 发布工具 - 3.6. 镜像拉取鉴权和策略

3.6. 镜像拉取鉴权和策略 今天我们解决镜像拉取鉴权和策略 镜像拉取鉴权 拉取私有镜像或私有仓库镜像的时候, 需要提供鉴权信息。 在 Kubernets 中, 通过 Secret 管理账号这些账号信息。 Secret 类型分为两种, kubernetes.io/dockerconfigjson: 如果有linux安装了 docker, 就是 ~/.docker/config.json 这个文件。 kubernetes.io/dockercfg: 不太熟。 在 /pkg/tokube/pod.go 中, 可以看到 ImagePullSecrets 的处理方法。 就是将字符串转为 kubernetes 的……

阅读全文

从零开始写 k8s 发布工具 - 3.5. 为 Container 添加健康检查方法

3.5. 为 Container 添加健康检查方法 kustz 终于到了准生产的地步了。 今天的健康检查接口, 就为我们解决这个问题。 我们要知道, 确定一个应用能不能对外提供服务之前, 需要进行一个 可用性 检测。 而这个检测通常被我们称为 健康检查。 Kubernetes 的健康检查 在 Kubernetes 中, 为我们提供了 主要 的 3类状态 的健康检查。 startup: 等待探针。 如果执行成功,……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它