Your Search Bar For Shrewd Tips

How Do I Clear Kubernetes Cache?


If a Kubernetes change is not showing up, a cached value may be responsible—but Kubernetes does not have one universal “cache” to clear. The Kubernetes API server, kubectl, container runtime, DNS services, and applications can each retain different data. Clearing the wrong cache can waste time or disrupt a running workload.

To clear Kubernetes cache safely, first identify what appears stale: command-line resource information, a container image, a DNS lookup, or an application response. Then refresh only the relevant cache. This guide explains the common types of Kubernetes cache, the commands used to clear or refresh them, and the precautions to take before making changes.

What Does “Kubernetes Cache” Mean?

Kubernetes is a collection of components, not a single program with one cache directory. When people ask how to clear Kubernetes cache, they may mean any of the following:

  • kubectl discovery or HTTP cache: Local information kubectl stores about API resources and API responses.
  • Container image cache: Images already downloaded to a node by its container runtime.
  • DNS cache: Cached name lookups in CoreDNS, NodeLocal DNSCache, an application, or a node’s operating system.
  • Application cache: Data held inside a pod, such as cached API responses, configuration, or database results.
  • Tooling cache: Cached chart indexes or package data used by tools such as Helm.

The Kubernetes API server is not normally cleared using a general-purpose cache command. If kubectl shows unexpected results, check which context and namespace you are using before removing local files. If a pod is serving old content, the cause may be an unchanged image tag or application behavior rather than a Kubernetes cache.

Clear the kubectl Cache

kubectl can cache API discovery information and some HTTP responses on the machine where the command runs. This cache may be worth refreshing if a newly installed custom resource definition is not appearing in commands, or if kubectl seems to have outdated API discovery data.

The default cache directory is usually ~/.kube/cache on Linux and macOS. The location can differ if you use a custom cache directory, set environment variables, or run kubectl under another user. You can remove the discovery cache alone to make kubectl retrieve API resource information again:

rm -rf ~/.kube/cache/discovery

To remove the HTTP cache as well, use:

rm -rf ~/.kube/cache/http

These commands remove local cache files; they do not delete Kubernetes resources or alter your cluster. Close any active kubectl commands first. The cache will be recreated as needed the next time you use kubectl. If you prefer, remove the whole cache directory instead:

rm -rf ~/.kube/cache

Be careful not to confuse ~/.kube/cache with ~/.kube/config. The config file contains cluster connection details, contexts, and credentials. Deleting it can prevent you from connecting to your clusters.

On Windows, locate the kube cache directory under your user profile, commonly in .kube\cache, and remove the relevant cache folder using File Explorer or PowerShell. If kubectl uses a custom cache directory, remove that location instead. After clearing the cache, retry the command and confirm that kubectl is connected to the expected context.

Refresh Kubernetes Container Images

Each Kubernetes node’s container runtime keeps downloaded images so containers can start without downloading the same image again. This is useful for performance, but it can cause confusion when an image tag—especially a mutable tag such as latest—is reused for a newer build.

First check the image name and pull policy in the workload specification. For deployments that should check the registry whenever a container starts, you can set:

imagePullPolicy: Always

This tells the kubelet to check the image registry when starting the container. It does not automatically remove every image stored on the node. For production deployments, using a unique version tag or an immutable image digest is generally more reliable than repeatedly overwriting a tag.

If you need to remove a specific image from a node, use the container runtime’s supported tools and target the correct node. With a CRI-compatible runtime, an administrator may be able to inspect and remove images with crictl:

crictl images
crictl rmi <image>

These commands must run where the runtime is accessible and may require elevated permissions. The exact steps vary by cluster provider and runtime. A managed Kubernetes service may not allow direct access to worker nodes, and removing an image that is in use may fail or affect workloads when containers are recreated.

Deleting a pod is not the same as clearing the node’s image cache. A replacement pod may use the same locally stored image, depending on its pull policy and image reference. Avoid manually deleting container-runtime storage directories: doing so can damage runtime metadata or disrupt workloads. Use supported runtime commands or your provider’s documented node-maintenance process.

Clear or Refresh Kubernetes DNS Cache

DNS problems can look like stale Kubernetes data. A pod may continue resolving a service to an old address, fail to resolve a recently created service, or return different results from different locations. Several layers may be involved: CoreDNS, NodeLocal DNSCache, the node operating system, and the application itself.

Start by checking whether the problem affects one pod or many. You can test DNS from an existing pod that has suitable tools installed, or start a temporary diagnostic pod if your cluster policy allows it. For example:

kubectl exec -it <pod-name> -- nslookup <service-name>.<namespace>.svc.cluster.local

Check that the service and endpoints are correct before restarting DNS components:

kubectl get service -n <namespace>
kubectl get endpoints -n <namespace>

CoreDNS commonly caches DNS responses in memory according to its configuration and the records’ time-to-live values. If you have confirmed a CoreDNS issue and your cluster uses the standard CoreDNS deployment, an administrator can restart its pods with:

kubectl rollout restart deployment/coredns -n kube-system

Names and namespaces vary between clusters, so inspect the actual DNS deployment first. A rollout restart briefly replaces DNS pods and should be done with care, particularly in a production cluster. If your cluster uses NodeLocal DNSCache, restarting CoreDNS alone may not clear the node-local cache. Follow the cluster provider’s guidance for that setup.

Some applications cache DNS results inside the process. In that case, restarting the affected application pod may be necessary after verifying the service record and DNS infrastructure. Restarting pods just to clear a suspected cache can cause downtime or interrupt jobs, so use a controlled rollout and check readiness settings first.

Refresh Helm and Other Local Tool Caches

If the issue involves a Helm chart that appears out of date, refresh the repository indexes rather than changing the Kubernetes cluster:

helm repo update

This fetches current repository metadata for configured Helm repositories. If a local index is damaged or remains stale, Helm’s cache location depends on your Helm version, operating system, and configuration. Check the configured paths with helm env before removing files. Avoid deleting Helm configuration or repository credentials when you only intend to refresh cached index data.

Other deployment tools may also cache manifests, plugins, or build artifacts. Use the tool’s documented refresh or clean command, and confirm whether the cache is local to your workstation, stored in a CI runner, or held by a remote build service. Clearing a local cache will not necessarily refresh a remote cache.

When Restarting a Pod Helps—and When It Does Not

A pod restart can clear data held only in that pod’s memory or writable container filesystem. It may help when an application has cached a response, configuration value, or DNS result that it does not refresh on its own. For a Deployment, a controlled restart is commonly performed with:

kubectl rollout restart deployment/<deployment-name> -n <namespace>
kubectl rollout status deployment/<deployment-name> -n <namespace>

This does not clear kubectl’s local cache, remove images from nodes, or refresh every DNS layer. It replaces pods according to the workload’s rollout strategy, so verify that the Deployment has enough healthy replicas and suitable disruption settings before proceeding. For a StatefulSet or another workload type, follow its specific operational guidance.

If configuration was supplied through a ConfigMap or Secret, confirm whether the application supports live reload. Many applications read configuration only at startup, so a rollout may be needed after an update. Also verify that the workload references the intended object and that the updated value is actually present.

How to Choose the Right Cache to Clear

Use the symptom to narrow down the likely cache before making changes:

  • kubectl does not list a new API resource: Check the active context and permissions, then refresh the kubectl discovery cache.
  • A pod runs old application code: Check the image tag or digest, pull policy, and node image; do not assume deleting the pod clears the image.
  • A service name resolves incorrectly: Check the service, endpoints, DNS configuration, and application-level DNS caching.
  • An application returns old data: Investigate the application’s own cache, backend, or configuration before restarting infrastructure.
  • A Helm chart appears outdated: Run helm repo update and verify the chart version and repository.

Before any cluster-wide action, check the current context and namespace with kubectl config current-context and kubectl config view --minify. For changes that restart workloads or shared services, review the impact, use a maintenance window when appropriate, and monitor the rollout afterward.

Conclusion

There is no single command to clear Kubernetes cache because different components cache different kinds of data. Remove kubectl’s local discovery cache when API resource information is stale, refresh image handling through the correct pull policy or runtime tooling, and investigate DNS at the CoreDNS, node-local, and application layers. For old application responses, inspect the application’s own behavior before restarting pods.

The safest approach is to identify where the stale data lives, use that component’s supported refresh method, and verify the result. Avoid deleting broad system directories or restarting shared services without understanding the impact. A targeted cache refresh is usually faster—and safer—than clearing everything.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →