## Cheat sheet for production environment 

In the following section we list some of the commands that are commonly used in a production environment. 

## Use kubectl drain to remove a node from service 

You can use kubectl drain  to safely evict all of your pods from a node before you perform maintenance on the node (for example for kernel upgrade or hardware maintenance). Safe evictions allow the pod’s containers to  gracefully terminate and respect the PodDisruptionBudgets that you have specified: 

1. First, identify the name of the node you wish to drain. You can list all of the nodes in your cluster with: 

kubectl get nodes 

2. Next, tell Kubernetes to drain the node: 

kubectl drain <node name> 

3. Once it returns without giving an error, you can power down the node (or on a cloud platform, delete the virtual machine backing the node). If you leave the node in the cluster during the maintenance operation, you need to run: 

kubectl uncordon <node name> 

This will instruct Kubernetes that it can resume scheduling of new pods onto the node. 

## Enabling autocomplete for kubectl 

It might be difficult to remember all of the commands and their arguments for the kubectl command. kubectl provides an autocomplete function  to help you remember the commands and their arguments. You can enable kubectl autocompletion in your current shell using the following command: 

## Removing a pod from a service 

source <(kubectl completion bash) 

Let’s assume we have a service backed by a number of pods. If one of the pods starts misbehaving we need to find out the root cause for the same. We need to remove the failing pod from the list of pods to investigate the problem later. 

Suppose we have pod foo with the label ‘test’. We update the pod  foo  by removing the label named test  if it exists with the following command: 

$ kubectl label pods foo test- 

As you remove the label, the pod will be out of service and deployment will spawn a new pod with the label test. 

## Editing kubernetes resources 

Sometimes in a production environment you need to fine tune Kubernetes resources by editing them. You can edit the resources using kubectl edit <resource_name>. 

