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

<pre><code>$ kubectl taint nodes \
          172.4.5.2-3a1d4eeb \
          kops.k8s.io/instancegroup=loadbalancer \
          NoSchedule
</code></pre>

AhmFM
<p>Use the <code>-o yaml</code> 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 <code>kubectl apply -f</code> , 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 )</p>

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

<pre><code>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
</code></pre>

<p>then use the yaml with kubectl apply:</p>

<pre><code>apiVersion: v1
kind: Node
metadata:
  name: minikube
spec:
  taints:
  - effect: PreferNoSchedule
    key: dedicated
    value: foo
</code></pre>
