GoogleContainerTools/skaffold · error
getting Kubernetes client: %w
Error message
getting Kubernetes client: %w
What it means
Task.jobsManager obtains a Kubernetes clientset (kubernetesclient.Client for the task's kubecontext) to get a Job interface. If client construction fails — bad kubeconfig, unreadable context, or client init error — it returns 'getting Kubernetes client'. Callers are Exec and Cleanup, so this can hit during both run and teardown.
Source
Thrown at pkg/skaffold/actions/k8sjob/task.go:149
Name: e.Name,
Value: e.Value,
})
}
}
func (t Task) Cleanup(ctx context.Context, out io.Writer) error {
jm, err := t.jobsManager()
if err != nil {
return err
}
return k8sjobutil.ForceJobDelete(ctx, t.Name(), jm, t.kubectl)
}
func (t Task) jobsManager() (typesbatchv1.JobInterface, error) {
clientset, err := kubernetesclient.Client(t.kubectl.KubeContext)
if err != nil {
return nil, fmt.Errorf("getting Kubernetes client: %w", err)
}
return clientset.BatchV1().Jobs(t.jobManifest.Namespace), nil
}
func (t Task) getContainerToDeploy() corev1.Container {
return corev1.Container{
Name: t.cfg.Name,
Image: t.artifact.Tag,
Command: t.cfg.Command,
Args: t.cfg.Args,
Env: append(t.getK8SEnvVars(t.cfg.Env), t.envVars...),
}
}
func (t Task) getK8SEnvVars(envVars []latest.VerifyEnvVar) (k8sEnvVar []corev1.EnvVar) {
for _, envVar := range envVars {
k8sEnvVar = append(k8sEnvVar, corev1.EnvVar{Name: envVar.Name, Value: envVar.Value})View on GitHub (pinned to a1189de023)
Solutions
- Validate the kubeconfig: kubectl config current-context and kubectl auth can-i get jobs --context <ctx> to ensure the context resolves and is authorized.
- Fix KUBECONFIG / kubeContext setting in skaffold.yaml to point at a valid config file containing the context.
- Regenerate credentials for the context (e.g. gcloud container clusters get-credentials) if the kubeconfig is stale.
Example fix
// before echo $KUBECONFIG # /nonexistent/config // after export KUBECONFIG=$HOME/.kube/config kubectl config current-context # sanity check, then rerun skaffold
Defensive patterns
Strategy: validation
Validate before calling
// Verify kubeconfig resolves the context before running k8sjob actions
[ -f "${KUBECONFIG:-$HOME/.kube/config}" ] && kubectl config get-contexts "<ctx>" > /dev/null Try / catch
try {
await skaffold.run(...);
} catch (e) {
if (/getting Kubernetes client/.test(String(e))) {
console.error('Fix KUBECONFIG / kubeContext; ensure the context exists');
}
throw e;
} Prevention
- Set KUBECONFIG explicitly in CI environments (HOME may be unset)
- Regenerate kubeconfig after cluster recreation or context renames
- Validate contexts with kubectl config get-contexts in preflight scripts
When it happens
Trigger: Executing or cleaning up a k8sjob action where kubernetesclient.Client(kubeContext) fails: missing/invalid kubeconfig file, unknown context name, malformed kubeconfig YAML, or client-go construction error.
Common situations: KUBECONFIG env var pointing to a nonexistent file; context renamed after cluster deletion; kubeconfig with wrong apiVersion after manual editing; HOME not set in CI so default kubeconfig path unresolvable.
Related errors
- error getting Kubernetes dynamic client: %w
- error getting Kubernetes client: %w
- getting Kubernetes client: %w
- getting current cluster context: %w
- getting current namespace: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/88543034640b46bd.
Report an issue: GitHub.