Fix Slow Namespace Switching in Kubie

Kubie makes it easy to switch across k8s contexts and namespaces. kubie works seamlessly with kubectl and removes the need to specify a namespace or context with each invocation of kubectl sub-command.

I’ve been using kubie for almost a year and recommend it whole heartedly. The only issue I’ve encountered is that switching namespaces in large k8s clusters is quite slow. Initally, it took a few seconds to switch namespaces, but my most recent attempt took 30 seconds !!. That was the last straw and I decided to look for a solution.

Validate Namespaces

kubie ensures a namespaces exists before entering it by default. As part of validating whether a namespaces exists, kubie ends up listing all namespaces in a cluster.

To avoid the latency that comes with listing all namespaces in a large cluster, simply toggle the behavior.validate_namespaces setting to false.

Step 1

Open kubie’s config file

> kubie edit-config

Step 2

Append this section to your kubie config file.

    # Make sure the namespace exists with `kubectl get namespaces` when switching
    # namespaces. If you do not have the right to list namespaces, disable this.
    # Default: true
    validate_namespaces: false

Once kubie picks up the new setting, switching namespaces should be near instantaneous.

The Correctness vs Speed Tradeoff

validate_namespaces defaults to true for a good reason, it makes error states impossible. kubie ns non-existent-namespace will return an error.

Setting validate_namespaces to false improves the latency for switching namespaces at the cost of correctness. kubie ns non-existent-namespace will no longer return an error and in fact, the command will appear to succeed.

Choose wisely :)