Removing labels or annotations from K8s objects using Ansible
Just a small little trick worth recording. To remove a label,
annotation, or likely any other key from a Kubernetes object using
Ansible’s k8s
module, you must set that key to NULL.
- name: Remove Annotation Blah
k8s:
api_key: ""
state: present
definition:
apiVersion: v1
kind: Node
metadata:
name: varda.private.opequon.net
annotations:
blah: NULL
The above snippet removes the blah
annotation from this node object.
Certainly not intuitive…took me a good day or two of searching when I need this last year.