注解其他资源
在这一步骤中,我们将探索如何使用 kubectl annotate
命令为其他资源(例如 Deployment)添加注解。
- 在
/home/labex/project
目录下创建一个名为 deployment.yaml
的文件,内容如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: nginx
image: nginx
使用以下命令创建 Deployment:
kubectl apply -f deployment.yaml
- 使用
kubectl annotate
命令为 Deployment 添加注解:
kubectl annotate deployment my-deployment my-annotation-key=my-annotation-value
- 验证注解是否已添加到 Deployment:
kubectl describe deployment my-deployment
你应该会在输出中看到注解 my-annotation-key
,其值为 my-annotation-value
。