Skip to content

Instantly share code, notes, and snippets.

@krsna1729
Created October 8, 2018 16:15
Show Gist options
  • Save krsna1729/d4dedcc4db27c07ac49b8ab2b18affcd to your computer and use it in GitHub Desktop.
Save krsna1729/d4dedcc4db27c07ac49b8ab2b18affcd to your computer and use it in GitHub Desktop.
add label to a node from within the cluster
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kata-label-node
namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: node-labeler
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kata-label-node-rb
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: node-labeler
subjects:
- kind: ServiceAccount
name: kata-label-node
namespace: default
---
apiVersion: v1
kind: Pod
metadata:
name: kata-label-node-pod
spec:
serviceAccountName: kata-label-node
containers:
- name: test-container
image: lachlanevenson/k8s-kubectl
command: [ "sh", "-c"]
args:
- printenv MY_NODE_NAME;
kubectl get node $MY_NODE_NAME --show-labels;
kubectl label nodes $MY_NODE_NAME kata-runtime=true;
kubectl get node $MY_NODE_NAME --show-labels;
env:
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
restartPolicy: Never
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment