Home > Software engineering >  Can we add labels to Nodes using Helm template
Can we add labels to Nodes using Helm template

Time:01-22

I am trying to add labels to the nodes using helm chart, however getting error while deploying.

yaml template


apiVersion: v1
kind: Node
metadata:
  name: {{ index (lookup "v1" "Node" "" "").items 0 "metadata" "name" }} 
  labels:
    content-strange: "true"
  name: {{ index (lookup "v1" "Node" "" "").items 1 "metadata" "name" }}
  labels:
    content-strange: "true"
  name: {{ index (lookup "v1" "Node" "" "").items 2 "metadata" "name" }}
  labels:
    content-strange: "true"

Error

helm install famous famous.1.1.tgz -n famous-ns1
Error: INSTALLATION FAILED: rendered manifests contain a resource that already exists. Unable to continue with install: Node "10.x.x.x" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; label validation error: missing key "app.kubernetes.io/managed-by": must be set to "Helm"; annotation validation error: missing key "meta.helm.sh/release-name": must be set to "famous"; annotation validation error: missing key "meta.helm.sh/release-namespace": must be set to "famous-ns1"

CodePudding user response:

You can't use Helm to modify existing objects. Helm works by running its templating engine to construct complete Kubernetes manifests, and them submits them to the cluster. This process assumes that an object is wholly owned by Helm, and these objects don't already exist, and nothing other than helm upgrade will modify them.

The error you're getting here is in fact because the Node objects already exist; Kubernetes creates them when the actual nodes (physical machines, cloud instances, VMs) get created and are joined to the cluster. You can't modify these using Helm.

  • Related