首页 > 解决方案 > 使用过期时间注释 Kubernetes 资源

问题描述

我想在 Kubernetes 资源(rbac 定义对象)中添加注释作为到期时间。

如何添加注释作为到期时间。

伪代码如下所示,

 annotations:
   expiry-time: {{ current date + 1 hour }}

如何添加此自定义注释?自定义注释需要添加什么语言的代码?

标签: kubernetesannotations

解决方案


如果您使用 *nix shell,如 bash,您可以使用datecommand 和kubectl patchcommand 。

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'

✌️☮️


推荐阅读