Learn how to efficiently delete Kubernetes node labels using both imperative commands and the Kubernetes API in this comprehensive guide.
This document provides a quick reference for common Kubernetes kubectl commands related to taints and patching objects. It covers listing taints on nodes, adding a taint to a node, and updating API objects using strategic and JSON merge patches.
List taints on Kubernetes nodes:
kubectl get nodes -o json | jq '.items[].spec.taints' Add a taint to a node:
kubectl taint nodes <node-name> key=value:NoScheduleUpdate an API object using a strategic merge patch:
kubectl patch <resource> <name> -p '{ "spec": { "key": "new-value" } }'Update an API object using a JSON merge patch:
kubectl patch <resource> <name> --type merge -p '{ "spec": { "key": "new-value" } }'This document provides code examples for listing taints on Kubernetes nodes, adding a taint to a node, updating an API object using a strategic merge patch, and updating an API object using a JSON merge patch. It includes examples using kubectl, jq, and JSON path for retrieving and displaying taints, adding taints with specific keys, values, and effects, and patching deployments and pods using strategic and JSON merge patches. The examples demonstrate how to update replicas in deployments and add labels to pods.
This document provides code examples for the following Kubernetes operations:
Listing Taints on Kubernetes Nodes
This example uses kubectl, jq, and a JSON path to retrieve and display taints on all nodes:
kubectl get nodes -o json | jq '.items[].spec.taints'Example Output:
[
{
"key": "node.kubernetes.io/unreachable",
"effect": "NoSchedule",
"timeAdded": "2023-10-26T12:00:00Z"
}
]
null
...Adding a Taint to a Node
This example adds a taint to a node named "my-node" that prevents scheduling of pods without a matching toleration:
kubectl taint nodes my-node app=blue:NoScheduleThis command adds a taint with:
app
blue
NoSchedule
Updating an API Object Using a Strategic Merge Patch
This example updates the replicas field of a Deployment named "my-deployment" to 3:
kubectl patch deployment my-deployment -p '{"spec": {"replicas": 3}}'Explanation:
kubectl patch: Uses the patch command to update the resource.deployment my-deployment: Specifies the resource type and name.-p '{"spec": {"replicas": 3}}': Provides the patch data in JSON format, targeting the spec.replicas field.Updating an API Object Using a JSON Merge Patch
This example updates the labels of a Pod named "my-pod" using a JSON merge patch:
kubectl patch pod my-pod --type merge -p '{"metadata": {"labels": {"environment": "production"}}}'Explanation:
--type merge: Specifies the patch type as JSON merge patch.-p '{"metadata": {"labels": {"environment": "production"}}}': Provides the patch data in JSON format, adding the environment label with the value production.These examples demonstrate basic operations related to Kubernetes taints and patching API objects. Remember to adapt the commands and data to your specific needs and environment.
General:
Listing Taints:
jq command can be further customized to filter and display specific taint information. For example, to only show taints with the effect "NoSchedule": kubectl get nodes -o json | jq '.items[].spec.taints[] | select(.effect == "NoSchedule")'
Adding Taints:
kubectl taint nodes <node-name> key-= command.Patching Objects:
-p flag must be valid JSON and should target the specific fields you want to update.--dry-run=client flag with kubectl patch to simulate the patch operation without actually applying the changes. This is useful for testing your patch data.kubectl patch: You can also update Kubernetes objects by editing them directly using kubectl edit <resource> <name>. However, patching is generally preferred for automated updates.These notes provide additional context and considerations for working with taints and patching objects in Kubernetes. Always refer to the official Kubernetes documentation for the most up-to-date information and best practices.
| Command | Description |
|---|---|
| `kubectl get nodes -o json | jq '.items[].spec.taints'` |
kubectl taint nodes <node-name> key=value:NoSchedule |
Adds a taint to a specific node. |
kubectl patch <resource> <name> -p '{ "spec": { "key": "new-value" } }' |
Updates a Kubernetes resource using a strategic merge patch. |
kubectl patch <resource> <name> --type merge -p '{ "spec": { "key": "new-value" } }' |
Updates a Kubernetes resource using a JSON merge patch. |
This document provided a concise guide to essential Kubernetes commands for managing taints and patching objects. By understanding these commands and concepts, users can effectively control pod scheduling, update deployments, modify pod configurations, and perform other crucial Kubernetes operations. Remember to consult the official Kubernetes documentation for comprehensive information and best practices.
Operating etcd clusters for Kubernetes | Kubernetes | etcd is a consistent and highly-available key value store used as Kubernetes' backing store for all cluster data.
If your Kubernetes cluster uses etcd as its backing store, make sure you have a back up plan for the data.
You can find in-depth information about etcd in the official documentation.
Before you begin Before you follow steps in this page to deploy, manage, back up or restore etcd, you need to understand the typical expectations for operating an etcd cluster.
Quickstart: Deploy an Azure Kubernetes Service (AKS) cluster using ... | Learn how to quickly deploy a Kubernetes cluster using an Azure Resource Manager template and deploy an application in Azure Kubernetes Service (AKS).
Deploying Node.js apps in a local Kubernetes cluster | Learn how to deploy a Node.js app on Kubernetes and scale to millions of requests.
How to Debug Kubernetes 'Node Not Ready' Error | Node Not Ready error indicates a machine in a K8s cluster that cannot run pods. Learn about the causes of this problem and how to solve it.