This article will illustrate:
- How to Clear Cache of Cluster by Removing the “cache” Directory
- How to Clear Kubernetes Cluster by Removing Nodes and Pods?
- Conclusion
How to Clear Cache of Cluster by Removing the “cache” Directory?
Occasionally, users may face difficulty in starting or creating a new Kubernetes cluster. To resolve this problem, the user must clear the Kubernetes cache.
To clear the Kubernetes cache, look at the given steps.
Step 1: Open the “.kube” Directory
To clear the Kubernetes cache, first, open the “.kube” directory by navigating to the “C:\Users\<User-name>” directory:
Step 2: Clear Kubernetes Cache
The “.kube” folder contains the cache folder that stores the Kubernetes cache. Open the “cache” directory:
This directory will contain two folders, the “discovery” directory and “http”. The discovery directory is utilized to store the “kubectl api-resource” request for each Kubernetes cluster. In contrast, the “http” directory is used to store the response body that is generated against each “api-resource” request.
To clear the Kubernetes cache, press the “CTRL+A” to select all directories. After that, press the “Delete” or “Del” key to clear the cache folder:
Here, you can see we have effectively deleted and cleared the Kubernetes cache:
How to Clear Kubernetes Cluster by Removing Nodes and Pods?
Kubernetes cluster does not have a centered or global Kubernetes cache. The Kubernetes command line tool “kubectl” does not provide any command to clear the cluster cache. The Kubernetes cluster cache can belong to a Kubernetes component or application such as pods and nodes. To clear the Kubernetes cluster, go through the below demonstration.
Step 1: Gets Pods
To get the Kubernetes cluster pods, utilize the “kubectl get pods” commands:
Step 2: Delete Pods
Next, delete the pods to clear the cluster using the “kubectl delete pod <pod-name>” command:
Step 3: Get Nodes
To completely clear the cluster cache or application cache running in the Kubernetes cluster, get the nodes using the “kubectl get nodes” command:
Step 4: Drain the Node
Next, drain the node to make it unschedulable and remove the node directory data. To do so, use the below command:
Step 5: Delete Node
To completely delete the node, simple use the “kubectl delete node <node-name>” command:
That is all about removing the Kubernetes cache and clearing the Kubernetes cluster.
Conclusion
The Kubernetes cache does not have a centralized cache and does not offer any kubectl command. To clear the Kubernetes cache, open the “.kube” directory from the system “$Home” directory or User directory. After that, clear all content of the directory. To clear the Kubernetes cluster, remove the Kubernetes components such as pods. After that, drain the node and delete it using the “kubectl delete node <node-name>” command. This post has illustrated how to clear the cache of the Kubernetes cluster.