kubernetes - 使用过期时间注释 Kubernetes 资源
问题描述
我想在 Kubernetes 资源(rbac 定义对象)中添加注释作为到期时间。
如何添加注释作为到期时间。
伪代码如下所示,
annotations:
expiry-time: {{ current date + 1 hour }}
如何添加此自定义注释?自定义注释需要添加什么语言的代码?
解决方案
如果您使用 *nix shell,如 bash,您可以使用date
command 和kubectl patch
command 。
kubectl patch <k8s-resource> <resource-name> -p \
"{\"metadata\":{\"annotations\":{\"expiry-time\":\"`date -d '1 hour' '+%m-%d-%Y-%H:%M:%S'`\"}}}"
如果您在 Mac 上,您可以将date
命令替换为:
date -v+1d '+%m/%d/%Y -%H:%M:%S'
✌️☮️
推荐阅读
- python - 不使用 sort() 按字母顺序对单词列表进行排序
- javascript - Jquery如何将类附加到生成的数组数字?
- tensorflow - 使用 tensorflow + opencv 引发 e.ag_error_metadata.to_exception(e)
- javascript - React 路由器更改 url 但不更改组件 [已解决]
- mongoose - MongoDB Atlas 按引用的文档字段搜索词搜索
- php - Laravel 7 - 由于登录尝试失败而重定向回来后如何在登录表单中显示旧输入?
- javascript - 购物车增量和减量值 JS
- sql-server - 连接到 LocalDB SQL Server Named Instance 的“服务器名称”的正确格式
- reactjs - 避免重新渲染组件
- html - 为 HTML/CSS 页面缩小窗口时滚动不可用