kubernetes/kubernetes · error
unable to locate encoder -- %q is not a supported media type
Error message
unable to locate encoder -- %q is not a supported media type
What it means
When writing the default config (--write-config-to), kube-proxy asks the codec factory for a serializer matching runtime.ContentTypeYAML. If no YAML serializer is registered in proxyconfigscheme.Codecs, SerializerInfoForMediaType returns !ok and the error 'unable to locate encoder -- "application/yaml" is not a supported media type' is returned (options.go:415).
Source
Thrown at cmd/kube-proxy/app/options.go:415
// run the proxy in goroutine
go func() {
err := o.proxyServer.Run(ctx)
o.errCh <- err
}()
for {
err := <-o.errCh
if err != nil {
return err
}
}
}
func (o *Options) writeConfigFile() (err error) {
const mediaType = runtime.ContentTypeYAML
info, ok := runtime.SerializerInfoForMediaType(proxyconfigscheme.Codecs.SupportedMediaTypes(), mediaType)
if !ok {
return fmt.Errorf("unable to locate encoder -- %q is not a supported media type", mediaType)
}
encoder := proxyconfigscheme.Codecs.EncoderForVersion(info.Serializer, v1alpha1.SchemeGroupVersion)
configFile, err := os.Create(o.WriteConfigTo)
if err != nil {
return err
}
defer func() {
ferr := configFile.Close()
if ferr != nil && err == nil {
err = ferr
}
}()
if err = encoder.Encode(o.config, configFile); err != nil {
return errView on GitHub (pinned to b882c60b40)
Solutions
- Use a stock kube-proxy build where YAML is registered in the proxy config scheme.
- Ensure kubeproxyconfig/v1alpha1 AddToScheme and the YAML codec are both wired before Codecs is used.
- If you only need JSON output and the build supports it, patch writeConfigFile to request JSON — but prefer fixing scheme registration.
- Rebuild from an unmodified source tree.
Defensive patterns
Strategy: validation
Validate before calling
// Verify a YAML serializer exists before calling --write-config-to.
func yamlEncoderAvailable() error {
for _, si := range proxyconfigscheme.Codecs.SupportedMediaTypes() {
if si.MediaType == runtime.ContentTypeYAML {
return nil
}
}
return fmt.Errorf("application/yaml is not a supported media type")
} Prevention
- Use stock kube-proxy builds where YAML is registered in the proxy config scheme.
- Do not strip codecs when forking the scheme.
- Keep config/v1alpha1 scheme registration intact.
When it happens
Trigger: A custom or stripped kube-proxy build where the YAML serializer was not added to the proxy config scheme, or scheme registration order omitted the YAML codec. The media type is hardcoded, so the value can never be the user's fault.
Common situations: A fork that rebuilt proxyconfigscheme.Scheme without YAML support; a binary built with an incompatible apimachinery codec factory; running --write-config-to against a malformed scheme init.
Related errors
- failed to add kube-proxy config API to lenient scheme: %w
- failed to add kube-proxy config v1alpha1 API to lenient sche
- failed to decode: %w
- unable to convert configz: %w
- encountered an error while tearing down rules
AI-assisted analysis of kubernetes/kubernetes@b882c60b40 (2026-08-07).
Data as JSON: /api/errors/a62a606e7c86a61a.
Report an issue: GitHub.