GoogleContainerTools/skaffold · error
getting k8s configuration: %w
Error message
getting k8s configuration: %w
What it means
This error is returned by GetAllPodNamespaces when it cannot load the current Kubernetes client configuration (kubeconfig) to determine the namespace of the current context. Skaffold wraps the underlying kubectx.CurrentConfig() failure with this message so callers know the failure happened while resolving which namespaces to watch. It only fires when no explicit namespace was passed, meaning the tool must fall back to the kubeconfig.
Source
Thrown at pkg/skaffold/deploy/util/namespaces.go:39
"sort"
kubectx "github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/kubernetes/context"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util"
)
// GetAllPodNamespaces lists the namespaces that should be watched.
// + The namespace passed on the command line
// + Current kube context's namespace
// + Namespaces referenced in Helm releases
func GetAllPodNamespaces(configNamespace string, pipelines []latest.Pipeline) ([]string, error) {
nsMap := make(map[string]bool)
if configNamespace == "" {
// Get current kube context's namespace
config, err := kubectx.CurrentConfig()
if err != nil {
return nil, fmt.Errorf("getting k8s configuration: %w", err)
}
context, ok := config.Contexts[config.CurrentContext]
if ok {
nsMap[context.Namespace] = true
} else {
nsMap[""] = true
}
} else {
nsMap[configNamespace] = true
}
// Set additional namespaces each helm release referenced
helmReleasesNamespaces, err := collectHelmReleasesNamespaces(pipelines)
if err != nil {
return nil, fmt.Errorf("collecting helm releases namespaces: %w", err)
}
for _, namespace := range helmReleasesNamespaces {View on GitHub (pinned to a1189de023)
Solutions
- Create or restore a valid kubeconfig (e.g. run `kubectl config view` to verify it parses, or re-run `gcloud container clusters get-credentials` / `az aks get-credentials`).
- Pass an explicit namespace (e.g. `skaffold dev --namespace myns`) so GetAllPodNamespaces skips kubeconfig resolution entirely.
- Fix the KUBECONFIG environment variable to point at an existing, valid kubeconfig file.
- Check that the current context in the kubeconfig is well-formed (run `kubectl config current-context`).
Example fix
// before
namespaces, err := util.GetAllPodNamespaces("", pipelines) // fails without kubeconfig
// after
namespaces, err := util.GetAllPodNamespaces("mynamespace", pipelines) // skips kubeconfig lookup Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight check before calling GetAllPodNamespaces
kubeconfig := os.Getenv("KUBECONFIG")
if kubeconfig == "" {
kubeconfig = filepath.Join(os.Getenv("HOME"), ".kube", "config")
}
if _, err := os.Stat(kubeconfig); err != nil {
return fmt.Errorf("kubeconfig not found at %s: %w", kubeconfig, err)
} Try / catch
// Wrap the call and surface kubeconfig remediation advice
namespaces, err := util.GetAllPodNamespaces(configNamespace, pipelines)
if err != nil && strings.Contains(err.Error(), "getting k8s configuration") {
log.Fatalf("k8s config unavailable: %v — run 'kubectl config view' or pass --namespace", err)
} Prevention
- Ensure a valid kubeconfig exists before running skaffold in CI or containers (mount or generate one).
- Always pass an explicit --namespace when running in environments without a kubeconfig.
- Validate with `kubectl config view` before invoking skaffold commands.
- Avoid stale KUBECONFIG env vars pointing at removed files.
When it happens
Trigger: Calling GetAllPodNamespaces with configNamespace == "" while kubectx.CurrentConfig() fails — typically when KUBECONFIG points to a missing/invalid file, the kubeconfig contains malformed YAML, or no kubeconfig exists at ~/.kube/config.
Common situations: Running skaffold dev in a fresh container/CI environment without a kubeconfig; a stale or corrupted ~/.kube/config after switching clusters; KUBECONFIG env var set to a nonexistent path; a context with a missing or malformed namespace entry.
Related errors
- resolving namespace: %w
- getting kubeconfig: %w
- unable to get kubernetes config: %w
- unable to get current kubernetes context: %w
- getting current namespace: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/d1a7aec9f0419677.
Report an issue: GitHub.