Taint a node in kubernetes live cluster

10/26/2018

How can I achieve the same command with a YAML file such that I can do a kubectl apply -f? The command below works and it taints but I can't figure out how to use it via a manifest file.

$ kubectl taint nodes \
          172.4.5.2-3a1d4eeb \
          kops.k8s.io/instancegroup=loadbalancer \
          NoSchedule
-- AhmFM
kubectl
kubernetes

1 Answer

10/26/2018

Use the -o yaml option and save the resulting YAML file and make sure to remove the status and some extra stuff, this will apply the taint , but provide you the yaml that you can later use to do kubectl apply -f , and save it to version control ( even if you create the resource from command line and later get the yaml and apply it , it will not re-create the resource , so it is perfectly fine )

Note: Most of the commands support --dry-run , that will just generate the yaml and not create the resource , but in this case , I could not make it work with --dry-run , may be this command does not support that flag.

C02W84XMHTD5:~ iahmad$ kubectl taint node minikube dedicated=foo:PreferNoSchedule -o yaml
apiVersion: v1
kind: Node
metadata:
  annotations:
    node.alpha.kubernetes.io/ttl: "0"
    volumes.kubernetes.io/controller-managed-attach-detach: "true"
  creationTimestamp: 2018-10-16T21:44:03Z
  labels:
    beta.kubernetes.io/arch: amd64
    beta.kubernetes.io/os: linux
    kubernetes.io/hostname: minikube
    node-role.kubernetes.io/master: ""
  name: minikube
  resourceVersion: "291136"
  selfLink: /api/v1/nodes/minikube
  uid: 99a1a304-d18c-11e8-9334-f2cf3c1f0864
spec:
  externalID: minikube
  taints:
  - effect: PreferNoSchedule
    key: dedicated
    value: foo

then use the yaml with kubectl apply:

apiVersion: v1
kind: Node
metadata:
  name: minikube
spec:
  taints:
  - effect: PreferNoSchedule
    key: dedicated
    value: foo
-- Ijaz Ahmad Khan
Source: StackOverflow