terraform-provider-kubernetes icon indicating copy to clipboard operation
terraform-provider-kubernetes copied to clipboard

Labeling default namespaces, pods, and deployment templates

Open KyleKotowick opened this issue 1 year ago • 1 comments

Terraform version, Kubernetes provider version and Kubernetes version

Terraform version: 1.9.5
Kubernetes Provider version: 2.32.0
Kubernetes version: 1.29.7

Question

I need to apply labels to the default namespace (kube-system), pods, and deployment templates that are automatically created for DNS in an Azure AKS cluster.

Through kubectl, I would do this like so:

kubectl label ns kube-system mylabel=myvalue
kubectl label pods -n kube-system coredns-... mylabel=myvalue
kubectl -n kube-system patch deployment coredns --patch '{"spec": {"template": {"metadata": {"labels": {"mylabel": "myvalue"}}}}}'

While these modifications can be done to new namespaces/pods/deployments created through Terraform resources, I cannot find a way to make these changes to existing default namespaces/pods/deployments. Is this possible? Preferably, a solution would avoid import blocks so that other existing configuration options aren't overwritten/deleted when the imported resource is applied.

KyleKotowick avatar Sep 12 '24 15:09 KyleKotowick

@KyleKotowick Have you had a look at the kubernetes_labels resource? I believe this is what you are looking for.

alexsomesan avatar Sep 25 '24 13:09 alexsomesan

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

github-actions[bot] avatar Sep 26 '25 00:09 github-actions[bot]